#P8922. 『MdOI R5』Squares

『MdOI R5』Squares

Background

This problem is not a data structure problem. It is recommended to solve F first.

1.gif

Problem Description

Given nn points on the plane, define a region on the plane as good if and only if it is a square with sides parallel to the coordinate axes and there is no given point strictly contained in it. Then there are mm queries. Each query gives a point (x,y)(x,y). For each query, find the side length of the largest good region that strictly contains (x,y)(x,y). If it can be infinitely large, output 1-1.

A point AA is strictly contained in a region BB if and only if AA is inside BB and not on its boundary.

To reduce tricky details, it is guaranteed that all the n+mn+m points have pairwise distinct xx-coordinates, and pairwise distinct yy-coordinates.

Input Format

The first line contains two positive integers n,mn,m.

The next nn lines each contain two integers x,yx,y, representing a given point (x,y)(x,y).

The next mm lines each contain two integers x,yx,y, representing the point (x,y)(x,y) given in a query.

Output Format

Output mm lines. Each line contains one integer. The integer on the ii-th line is the answer to the ii-th query.

4 2
1 0
0 3
4 1
3 4
2 2
5 5
4
-1

Hint

For 100%100\% of the data, 1n,m3×1051\le n,m\le 3\times 10^5, 0x,y1080\le x,y\le 10^8.

Subtask1(10%)\operatorname{Subtask} 1(10\%): n,m10n,m\le 10.

Subtask2(10%)\operatorname{Subtask} 2(10\%): n,m100n,m\le 100.

Subtask3(20%)\operatorname{Subtask} 3(20\%): n,m103n,m\le 10^3.

Subtask4(20%)\operatorname{Subtask} 4(20\%): n,m5×104n,m\le 5\times 10^4.

Subtask5(20%)\operatorname{Subtask} 5(20\%): n,m105n,m\le 10^5.

Subtask6(20%)\operatorname{Subtask} 6(20\%): no special constraints.

Sample Explanation 1

For the first query, the square with bottom-left corner (0,0)(0,0) and side length 44 is the largest good region that strictly contains (2,2)(2,2).

For the second query, the square with bottom-left corner (4,4)(4,4) and side length ++\infty is the largest good region that strictly contains (5,5)(5,5).

Translated by ChatGPT 5