#P8530. [Ynoi2003] 博丽灵梦
[Ynoi2003] 博丽灵梦
Problem Description
Counting colors in rectangles, with weights.
You are given a 2D plane with points. The -th point has coordinates and a weight .
You are given an array of length , indexed from to .
There are queries. Each query gives a rectangle . Define the set $S = \{ a_i \mid l_1 \le i \le r_1 \land l_2 \le p_i \le r_2 \}$. For all elements in the set , compute the sum of .
Input Format
The first line contains an integer .
The next line contains numbers, where the -th number denotes .
The next line contains numbers, where the -th number denotes .
The next line contains numbers, where the -th number denotes .
The next line contains an integer .
The next lines each contain numbers , describing one query.
Output Format
For each query, output one line containing an integer, which is the answer. Output the answer modulo .
9
9 8 7 6 2 4 5 3 1
1 1 4 5 1 4 1 9 1
9 1 1 4 5 1 4 1 9
9
4 9 3 6
2 9 1 8
3 8 2 4
3 9 2 7
2 8 1 6
1 9 1 9
1 3 5 7
2 3 3 3
6 6 6 6
27
27
22
27
27
27
4
0
0
Hint
Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078.
Sample Explanation
For the query whose answer is , , the corresponding , and the sum is .
For the query whose answer is , , the corresponding , and the sum is .
For the query whose answer is , , the corresponding , and the sum is .
For the query whose answer is , , and the sum is .
Constraints
The specific limits for each test point are shown in the table below:
| Test Point ID | Special Constraint | ||
|---|---|---|---|
| None | |||
| None | |||
| None | |||
For convenience, we write to mean that two points and on the plane satisfy and .
Special constraint A: For all queries, and .
Special constraint B: This special constraint is too easy to exploit for weak testdata, so it is removed.
Special constraint C: At most pairs do not satisfy .
For all test points: , , , . It is guaranteed that is a permutation, and .
Translated by ChatGPT 5