#P5268. [SNOI2017] 一个简单的询问
[SNOI2017] 一个简单的询问
Problem Description
You are given a sequence of length , where , and queries. For each query, you are given , and you need to output
$$\sum\limits_{x=0}^\infty \text{get}(l_1,r_1,x)\times \text{get}(l_2,r_2,x)$$Here, means the number of times the value appears in the interval .
Input Format
The first line contains an integer , the length of the sequence.
The second line contains integers, representing .
The third line contains an integer , the number of queries.
Lines to each contain four integers , representing a query.
Output Format
For each query, output one integer per line, representing the answer.
5
1 1 1 1 1
2
1 2 3 4
1 1 4 4
4
1
Hint
For of the testdata, .
For another of the testdata, .
For of the testdata, , , , .
The Constraints are the same as the original problem, but the testdata is made by LibreOJ and is not the original testdata.
Note: The answer may exceed the maximum value of int.
Translated by ChatGPT 5