#P6224. [BJWC2014] 数据

[BJWC2014] 数据

Description

To write his thesis, Alex often needs to organize a large amount of data. This time, Alex faces a serious challenge: he needs to implement a data structure to maintain a set of points.

Now there are NN points on a 2D plane.

Alex needs to support the following three operations:

  1. Add a point to the set.

  2. Given a point, query the minimum Manhattan distance from it to all points in the set.

  3. Given a point, query the maximum Manhattan distance from it to all points in the set.

The Manhattan distance between two points is defined as the sum of the absolute difference of their xx-coordinates and the absolute difference of their yy-coordinates.

Such a difficult problem is of course beyond Alex, so he has to ask you for help again.

Input Format

The first line contains an integer NN, indicating the initial number of points in the set.

The next NN lines each contain two integers, representing the xx-coordinate and yy-coordinate of a point.

Line N+2N + 2 contains an integer QQ, indicating the number of queries.

The next QQ lines each contain three integers, representing the query type, the xx-coordinate, and the yy-coordinate. Type 00 means adding a point, type 11 means querying the minimum Manhattan distance to that point, and type 22 means querying the maximum.

Output Format

Output several lines, in order, each being the answer to a query operation.

3
7 5
6 2
3 1
5
1 6 1
1 5 5
2 7 1
0 3 2
1 1 0
1
2
4
3

Hint

For the first 20%20\% of the testdata: 1N,Q1031 \le N, Q \le 10^3.

For 100%100\% of the testdata: 1N,Q1051 \le N, Q \le 10^5.

The coordinates of points are non-negative integers not exceeding 10910^9.

Translated by ChatGPT 5