Greatest Square

아직 제출이 없습니다시간 제한8초메모리 제한512 MB

문제

Grete has a polygon consisting of nn vertices. All sides of the polygon are parallel to the coordinate axes, and each two adjacent sides of the polygon are perpendicular. It is guaranteed that the polygon is simple, that is, it doesn't have self-intersections and self-touches.

Grete has mm queries and in each query, a point (u_i,v_i)(u\_i, v\_i) strictly inside the polygon is given. Grete would like to know the length of the side of the maximal square inside the polygon whose lower left corner is (u_i,v_i)(u\_i, v\_i).

입력

The input consists of several test cases terminated by end-of-file. For each test case:

The first line contains two integers nn and mm, which are the number of vertices and the number of queries.

Each of the next nn lines contains two integers x_ix\_i and y_iy\_i, the coordinates of vertices of the polygon in counterclockwise order.

Each of the next mm lines contains two integers u_iu\_i and v_iv\_i, the coordinates of the lower left corner.

출력

For each query, output an integer denoting the length of the maximal square inside the polygon.

제한

  • 4n2×1054 \leq n \leq 2 \times 10^5
  • 1m2×1051 \leq m \leq 2 \times 10^5
  • 108x_i,y_i,u_i,v_i108-10^8 \leq x\_i, y\_i, u\_i, v\_i \leq 10^8
  • The sum of nn and the sum of mm do not exceed 2×1062 \times 10^6.