#P6108. [Ynoi2009] rprsvq

[Ynoi2009] rprsvq

Problem Description

You have a sequence v1,v2,,vnv_1, v_2, \dots, v_n of length nn, with all initial values equal to 00.

You need to perform mm operations:

  • Operation 1: Given l,r,al, r, a, add aa to vl,vl+1,,vrv_l, v_{l+1}, \dots, v_r.
  • Operation 2: Given l,rl, r, choose a non-empty subsequence from vl,vl+1,,vrv_l, v_{l+1}, \dots, v_r. For all possible choices, compute the sum of variances of the chosen subsequences. Output the answer modulo 998244353998244353.

The variance of a sequence a1,a2,,ana_1, a_2, \dots, a_n is defined as follows. Let aˉ=1ni=1nai\bar{a}=\frac{1}{n}\sum_{i=1}^n a_i, then the variance is 1ni=1n(aiaˉ)2\frac{1}{n}\sum_{i=1}^n (a_i-\bar{a})^2.

Input Format

The first line contains two integers n,mn, m.

The next mm lines describe the operations. Each line contains either four integers 1 l r a1~l~r~a or three integers 2 l r2~l~r, representing an operation of the first type or the second type. It is guaranteed that 0a<9982443530\leq a< 998244353.

Output Format

For each operation of the second type, output one line containing the answer.

4 4
1 2 4 1
2 1 3
1 1 2 2
2 1 4
388206138
339680376
10 20
1 4 4 520968631
1 4 7 988452236
1 4 9 355405133
2 9 10
2 2 8
1 3 5 400339337
2 3 8
2 6 7
2 4 10
2 7 9
1 3 8 387471594
1 2 4 559944503
2 1 8
1 4 7 108832063
2 5 9
2 4 8
1 3 8 622785003
2 9 10
1 2 7 252591713
1 5 6 666406180
570099967
274921471
285269733
0
571283655
970723747
401326984
17519114
844628984
570099967

Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078.

Constraints:

For 10%10\% of the testdata, n10,m1000n\leq 10, m\leq 1000.

For 20%20\% of the testdata, n16,m1000n\leq 16, m\leq 1000.

For 30%30\% of the testdata, n100,m103n\leq 100, m\leq 10^3.

For 50%50\% of the testdata, n,m103n, m\leq 10^3.

For another 10%10\% of the testdata, n105n\leq 10^5, and it is guaranteed that all operations of the first type come first, followed by operations of the second type.

For 80%80\% of the testdata, n,m105n, m\leq 10^5.

For 100%100\% of the testdata, 1n5×106,1m1051\leq n \leq 5\times 10^6, 1\leq m\leq 10^5.

For the first query in the first testdata, the sequence is {0,1,1}\{0,1,1\}. Among all subsequences, only {0,1}\{0,1\}, {0,1}\{0,1\}, and {0,1,1}\{0,1,1\} have non-zero variance, which are 14,14,29\frac{1}{4}, \frac{1}{4}, \frac{2}{9} respectively. Their total sum is 1318\frac{13}{18}.

Translated by ChatGPT 5