#P12518. 「MSTOI-R1」Easy question
「MSTOI-R1」Easy question
Problem Description
You are given a sequence of length . You need to process the following three types of operations:
-
1 l rmeans to compute . -
2 l r kmeans to compute . -
3 l rmeans to compute $(r-l+1)\cdot \sum\limits_{i=l}^r \left(a_i-\overline a\right)^2$, where is the average of the subsequence .
Output each answer modulo .
Input Format
The first line contains two integers , representing the length of the sequence and the number of queries.
The second line contains integers representing the sequence .
The next lines each contain one operation. The format is described in the statement.
Output Format
Output a total of lines. Each line contains one integer, representing the answer to that query.
5 4
1 5 4 2 3
1 3 5
1 1 5
2 1 3 3
3 2 3
9
15
190
1
Hint
Sample Explanation:
For the first query, compute the sum over . The answer is .
For the second query, compute the sum over . The answer is .
For the third query, the answer is .
For the fourth query, the average over is . The answer is $(3-2+1)\times((5-4.5)^2+(4-4.5)^2)=2\times(0.25+0.25)=1$.
Constraints:
For of the testdata, .
For another of the testdata, there are only type queries.
For another of the testdata, there are only type queries.
For of the testdata, . These test points include those with only type queries and those with only type queries.
For of the testdata, $1\leq n,q\leq 10^6, 1\leq k\leq 20, 1\leq a_i\leq 10^9$.
It is guaranteed that the answers to all queries are integers.
The input and output for this problem are large, so be sure to use fast I/O.
Translated by ChatGPT 5