Greatest Square
Time limit8sMemory limit512 MB
Given a rectilinear simple polygon and query points, find the largest axis-parallel square inside it with each point as its lower left corner.
- Level
Hard9 of 10
- Topics
- Geometry, Segment tree, Binary search
- Solved
- No attempts yet
Problem
Grete has a polygon with vertices. All sides of the polygon are parallel to the coordinate axes, and each pair of adjacent sides is perpendicular. The polygon is simple, so it has no self-intersections and no self-touches.
Grete has queries. Each query gives a point strictly inside the polygon. For each point, Grete wants the side length of the largest square that lies inside the polygon and has as its lower left corner.
Input
The input consists of several test cases and ends at end-of-file. Each test case has the following format.
The first line contains two integers and , the number of vertices and the number of queries.
Each of the next lines contains two integers and , the coordinates of the vertices in counterclockwise order.
Each of the next lines contains two integers and , the coordinates of the lower left corner of a query.
Output
For each query, print one integer on its own line: the side length of the largest square inside the polygon whose lower left corner is the query point.
Constraints
- The sum of and the sum of do not exceed .