#P10511. 方差
方差
Background
Define the variance of a sequence of length as:
Here, is the summation symbol. For example, . is the average of the sequence .
For example, for the sequence , . Then $s^2=\frac{1}{n} \sum_{i=1}^n (a_i-\overline{a})^2=\frac{1}{5}[(3-3)^2+(5-3)^2+(1-3)^2+(4-3)^2+(2-3)^2]=2$.
Problem Description
Xiao S thinks math is very easy, so Xiao R wants to test her.
Xiao R gives Xiao S a sequence . This sequence consists of segments. The -th segment is given as l r b, meaning are all equal to . It is guaranteed that any two given intervals do not overlap.
Now, Xiao R has queries. Each query is of the form l r, asking you to query the variance of the interval (note that may equal , in which case the variance of this interval is ).
Since the number may be a decimal, Xiao R finds it inconvenient to judge the answer directly, so he wants Xiao S to compute . It can be proven that is always an integer.
As Xiao S’s good friend, can you help her?
Input Format
The first line contains three positive integers , representing the length of the sequence, the number of segments, and the number of queries.
The next lines each contain three positive integers, representing .
The next lines each contain two positive integers . You need to answer the variance for .
Output Format
For each query, output one integer per line, representing your answer.
5 3 15
1 1 5
2 2 7
3 5 8
1 1
1 2
1 3
1 4
1 5
2 2
2 3
2 4
2 5
3 3
3 4
3 5
4 4
4 5
5 5
0
4
14
24
34
0
1
2
3
0
0
0
0
0
0
Hint
Sample Explanation
The sequence is . For the 12th query, the average of interval is , and the variance is $s^2 = \frac{1}{3} [(8 - 8)^2 + (8 - 8)^2 + (8 - 8)^2] = 0$.
Constraints
- For of the testdata, .
- For of the testdata, and .
- For another of the testdata, and .
- For another of the testdata, .
For all testdata, it is guaranteed that:
- , , , , .
- The testdata guarantees that for any , , and and do not intersect, i.e. .
- The testdata guarantees that if we take the union of all , then it covers all positive integers on . That is: .
Translated by ChatGPT 5