#P6783. [Ynoi2008] rrusq

[Ynoi2008] rrusq

Problem Description

Given a 2D plane, there are nn key points, mm rectangles, and qq queries. Each key point has a weight aia_i.

A rectangle with bottom-left corner (xi,yi)(x_i,y_i) and top-right corner (xi,yi)(x'_i,y'_i) contains a point (a,b)(a,b) if and only if xiaxix_i\le a\le x'_i and yibyiy_i\le b\le y'_i.

In each query, you are given [l,r][l,r]. For a key point ii, if point ii lies in any rectangle whose index is within [l,r][l,r], then we say that point ii is jointly contained by the rectangles in interval [l,r][l,r]. Output the sum of weights of all key points jointly contained by the rectangles in interval [l,r][l,r].

Input Format

The first line contains an integer nn.

Then follow nn lines, each containing two elements pi,aip_i,a_i, meaning the ii-th key point is (i,pi)(i,p_i) with weight aia_i. It is guaranteed that pp is a permutation of 11 to nn.

Then one line contains an integer mm.

Then follow mm lines, each containing four elements xi,xi,yi,yix_i,x'_i,y_i,y'_i, meaning the bottom-left corner of the ii-th rectangle is (xi,yi)(x_i,y_i) and the top-right corner is (xi,yi)(x'_i,y'_i).

Then one line contains an integer qq.

Then follow qq lines, each containing two elements l,rl,r, meaning a query on interval [l,r][l,r].

Output Format

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

10
6 4
2 3
4 3
10 8
8 8
9 9
7 3
1 9
5 7
3 7
10
1 3 2 5
3 7 8 10
3 4 3 6
3 4 5 7
6 8 1 8
4 9 6 9
1 5 6 9
4 9 2 7
1 1 1 5
1 1 4 9
10
2 6
7 8
2 8
6 9
9 10
4 5
5 6
3 7
7 10
1 2
40
22
51
31
4
12
29
36
22
31

Hint

Idea: nzhtl1477&ccz181078, Solution: zx2003, Code: ccz181078, Data: nzhtl1477.

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 5%5\% of the testdata, it is Sample 1.

For another 14%14\% of the testdata, q=1q=1.

For another 19%19\% of the testdata, n,m,q500n,m,q\leq 500.

For another 19%19\% of the testdata, n,m500n,m\leq 500.

For another 19%19\% of the testdata, n,m,q2000n,m,q\leq 2000.

For 100%100\% of the testdata, 1n,m1051\leq n,m\leq 10^5, 1q1061\leq q \leq 10^6.

1ai100001\leq a_i \leq 10000, 1xixin1\leq x_i\leq x_i'\leq n, 1yiyin1\leq y_i\leq y_i'\leq n, 1lrm1\leq l\leq r\leq m

Translated by ChatGPT 5