Under construction

Still being built. Things may change

Voronoi Diagram Point Query

Time limit10sMemory limit1024 MB

Summary
Classify each query point by which Voronoi cells contain it: none, one region index, a bisector line of two, or a vertex of three or more.
Level

Medium7 of 10

Topics
Geometry, Brute force, Implementation
Solved
No attempts yet

Problem

Figure: Voronoi diagram of size 4.

In the 2-dimensional Cartesian coordinate system, we define the Voronoi diagram of a non-empty set of points SS as a diagram that divides the plane by the criterion "which point in the set SS is closest at this location?". More precisely, the Voronoi diagram of a given non-empty point set {P1, P2, ⋯ , Pn}\{P_1,\ P_2,\ \cdots,\ P_n\} is a collection of regions: a point KK is included in region ii if and only if d(Pi, K)≤d(Pj, K)d(P_i,\ K) \le d(P_j,\ K) holds for all 1≤j≤n1 \le j \le n, where d(X, Y)d(X,\ Y) is the Euclidean distance between points XX and YY.

For example, in the picture above, every location on the plane is colored by the closest point to that location. Points that belong to a single region are colored with a light color indicating that region, and points that belong to more than one region form lines and points colored black.

There is an algorithm that computes the Voronoi diagram in O(nlog⁡(n))\mathcal{O}(n \log(n)), but it is infamous for being very complicated and difficult. We are lenient problem setters, so we set n≤2000n \leq 2000, which means you can solve this task with slower Voronoi diagram algorithms.

In this task, you should solve the point query problem in a Voronoi diagram: in the Voronoi diagram constructed from the point set {P1, P2, ⋯ , Pn}\{P_1,\ P_2,\ \cdots,\ P_n\}, you should determine which region(s) the point belongs to. More precisely, you are given qq point queries. For each query point, you should determine the following:

  • If it is not included in any region, output NONE.
  • If it is included in exactly one region, output REGION X, where XX is the index of that region.
  • If it is included in exactly two regions, output LINE X Y, where XX and YY (XX < YY) are the indices of those two regions.
  • If it is included in three or more regions, output POINT.

Input

The first line gives the number of points forming the Voronoi diagram, nn, and the number of queries, qq. (3≤n≤2,000, 1≤q≤250,0003 \le n \le 2,000,\ 1 \le q \le 250,000)

The ii-th of the next nn lines gives two integers indicating the xx and yy coordinates of PiP_i. These are the points that form the Voronoi diagram. All nn points are distinct. (∣x∣, ∣y∣≤10,000|x|,\ |y| \le 10,000)

The jj-th of the next qq lines gives two integers indicating the xx and yy coordinates of QjQ_j. For each point QjQ_j, you should determine which region(s) it belongs to. (∣x∣, ∣y∣≤10,000|x|,\ |y| \le 10,000)

Output

The output consists of qq lines. In the jj-th line, print one of the following:

  • If QjQ_j is not included in any region, output NONE.
  • If QjQ_j is included in exactly one region, output REGION X, where XX is the index of that region.
  • If QjQ_j is included in exactly two regions, output LINE X Y, where XX and YY (XX < YY) are the indices of those two regions.
  • If QjQ_j is included in three or more regions, output POINT.

Examples1

  1. Example 1

    Input
    4 3
    -5 0
    0 5
    3 4
    1 -6
    -2 2
    0 0
    2 2
    
    Expected output
    LINE 1 2
    POINT
    REGION 3