#P12518. 「MSTOI-R1」Easy question

「MSTOI-R1」Easy question

Problem Description

You are given a sequence aa of length nn. You need to process the following three types of operations:

  1. 1 l r means to compute i=lrai\sum\limits_{i=l}^{r} a_i.

  2. 2 l r k means to compute i=lraik\sum\limits_{i=l}^{r} {a_i}^k.

  3. 3 l r means to compute $(r-l+1)\cdot \sum\limits_{i=l}^r \left(a_i-\overline a\right)^2$, where a\overline a is the average of the subsequence [l,r][l,r].

Output each answer modulo 998244353998244353.

Input Format

The first line contains two integers n,qn, q, representing the length of the sequence and the number of queries.

The second line contains nn integers representing the sequence aa.

The next qq lines each contain one operation. The format is described in the statement.

Output Format

Output a total of qq 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 [3,5][3,5]. The answer is 4+2+3=94+2+3=9.

For the second query, compute the sum over [1,5][1,5]. The answer is 1+5+4+2+3=151+5+4+2+3=15.

For the third query, the answer is 13+53+43=1+125+64=1901^3+5^3+4^3=1+125+64=190.

For the fourth query, the average over [2,3][2,3] is 5+42=4.5\frac{5+4}{2}=4.5. The answer is $(3-2+1)\times((5-4.5)^2+(4-4.5)^2)=2\times(0.25+0.25)=1$.

Constraints:

For 20%20\% of the testdata, 1n,q,ai100,1k31\leq n,q,a_i\leq 100, 1\leq k\leq 3.

For another 10%10\% of the testdata, there are only type 11 queries.

For another 10%10\% of the testdata, there are only type 22 queries.

For 70%70\% of the testdata, 1n,q1051\leq n,q\leq 10^5. These test points include those with only type 11 queries and those with only type 22 queries.

For 100%100\% 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