#P7290. 「EZEC-5」暴力出奇迹

「EZEC-5」暴力出奇迹

Description

Given a plane with nn vertical line segments. The ii-th segment has endpoints (i,ai)(i,a_i) and (i,bi)(i,b_i).

There are mm queries. Each query gives l,r,x,yl,r,x,y. Consider all horizontal segments connecting (x,i)(x,i) and (y,i)(y,i) for lirl\le i\le r. For these horizontal segments, ask what is the maximum number of vertical segments that a segment can intersect.

A vertical segment with endpoints (i,a1)(i,a_1) and (i,a2)(i,a_2) intersects a horizontal segment with endpoints (b1,j)(b_1,j) and (b2,j)(b_2,j) if and only if a1ja2a_1\le j\le a_2 and b1ib2b_1\le i\le b_2. Note that when two segments share an endpoint, if other segments pass through this shared point, it is still counted as an intersection.

Input Format

The first line contains an integer nn.

The next nn lines each contain two integers ai,bia_i,b_i, representing the two endpoints of the ii-th vertical segment. It is guaranteed that aibia_i \le b_i.

Then a line contains an integer mm.

The next mm lines each contain four integers, representing one query: l,r,x,yl,r,x,y.

Output Format

For each query, output one line with one integer, representing the answer.

10
1 8
5 9
5 6
2 8
3 7
4 5
3 7
6 7
3 9
5 10
10
2 4 2 5
5 9 8 10
2 9 3 6
3 7 6 9
1 10 2 9
4 5 1 7
9 10 4 9
2 3 6 9
1 7 6 7
3 10 3 4

2
3
4
3
7
7
1
2
2
2

Hint

Note: This problem uses bundled testdata. You can only get the score for a subtask after you pass all test points in that subtask.

For 100%100\% of the data, 1n5×1051\le n\le 5\times 10^5, 1m9×1051\le m\le 9\times 10^5, and 1l,r,x,y,ai,bin1\le l,r,x,y,a_i,b_i\le n.


Below are the old Constraints

For 5%5\% of the data, it is Sample 1.

For another 14%14\% of the data, m=1m=1.

For another 5%5\% of the data, n,m500n,m\leq 500.

For another 14%14\% of the data, n500n\leq 500.

For another 19%19\% of the data, n,m2000n,m\leq 2000.

For another 19%19\% of the data, n20000n\leq 20000.

For 100%100\% of the data, 1n5×1041\le n\le 5\times 10^4, 1m5×1051\le m\le 5\times 10^5, and 1l,r,x,y,ai,bin1\le l,r,x,y,a_i,b_i\le n.

Translated by ChatGPT 5