#P5142. 区间方差
区间方差
Description
For a sequence of length , , we define its mean as:
and define its variance as:
Now you are given a sequence of length . You need to support two operations. Each operation has the format c x y.
If , it is an update: set to .
If , it is a query: compute the variance of through (inclusive).
To avoid floating-point errors, output the result as a fraction modulo (mod ()).
Input Format
The first line contains two integers , meaning the sequence has length and there are operations.
The second line contains integers , representing the initial values of sequence .
Then there are lines, each in the format c x y, with meanings as described above. All operations are guaranteed to be valid.
Output Format
For each operation , output one line.
4 8
0 0 0 0
1 1 1
1 2 2
1 3 3
1 4 4
2 1 1
2 1 2
2 1 3
2 1 4
0
250000002
666666672
250000003
Hint
Explanation for Sample 1
After four updates, the sequence is: .
The variance of interval is .
The variance of interval is . The modular inverse of is .
The variance of interval is . The modular inverse of is , and .
Constraints
- For of the testdata, , .
- For of the testdata, , , . For operation , . For operation , .
Translated by ChatGPT 5
京公网安备 11011102002149号