P18123 [ICPC 2026 Seoul R] Drones

Description

The military base is represented by a simple polygon with at most $5$ sides. Note that a simple polygon is a polygon whose boundary does not intersect itself. More precisely, its edges intersect only at their common endpoints when they are consecutive edges, and nonconsecutive edges do not intersect. No three consecutive vertices of the polygon are collinear. The base monitors whether nearby drones are approaching its boundary. The plane is divided into three disjoint zones: the “Inner” zone, consisting of the interior and boundary of the base polygon; the “Boundary” zone, consisting of points strictly outside the base polygon whose shortest distance to its boundary is at most $d$; and the “Outer” zone, consisting of all remaining points. In particular, points on the polygon boundary belong to the Inner zone, while points outside the polygon at distance exactly $d$ from its boundary belong to the Boundary zone. The distance between a drone and the base is defined as the shortest distance from the drone to the base’s boundary. For every point in the Outer zone, its shortest distance $l$ to the polygon boundary satisfies $l>d$. All polygon vertices and drones have integer coordinates. The polygon vertices are pairwise distinct, and the drone positions are also pairwise distinct. A drone may have the same coordinates as a polygon vertex. Figure 1 illustrates two example bases. The boundary depicted by the dotted line outside the base represents the limit of the “Boundary” zone. For Base A, the drones located in the Inner, Boundary, and Outer zones are $\{D_3,D_6,D_8\}$, $\{D_1,D_2,D_7\}$, and $\{D_4,D_5\}$, respectively; for Base B, they are $\{D_1,D_2\}$, $\{D_5,D_6,D_7\}$, and $\{D_3,D_4\}$. The polygon boundary belongs exclusively to the Inner zone, and the outer boundary of the Boundary zone belongs exclusively to the Boundary zone. ![](https://cdn.luogu.com.cn/upload/image_hosting/dmdfvdcq.webp) **Figure 1.** Two example bases with drones (blue dots). The sample input and output for two test cases corresponding to Bases A and B, respectively. Given the coordinates of base vertices in counterclockwise order and the coordinates of $n$ observed drones, write a program to determine the number of drones located in each of the three zones: Inner, Boundary, and Outer.

Input Format

Your program is to read from standard input. The first line contains two integers $s$ and $d$ ($3\le s\le 5$; $1\le d\le 10{,}000$), where $s$ is the number of sides of the base polygon and $d$ is the maximum distance defining the Boundary zone. The second line contains $2s$ integers $x_1,y_1,x_2,y_2,\ldots,x_s,y_s$ ($1\le x_i,y_i\le 10{,}000$), representing the coordinates $(x_i,y_i)$ of the polygon’s vertices in counterclockwise order. The third line contains an integer $n$ ($1\le n\le 1{,}000$), the number of drones. Each of the next $n$ lines contains two integers $x'_j$ and $y'_j$ ($1\le x'_j,y'_j\le 10{,}000$), the coordinates $(x'_j,y'_j)$ of a drone.

Output Format

Your program is to write to standard output. Print exactly one line. Print three space-separated integers: the numbers of drones in the Inner, Boundary, and Outer zones, respectively.