#P6108. [Ynoi2009] rprsvq
[Ynoi2009] rprsvq
Problem Description
You have a sequence of length , with all initial values equal to .
You need to perform operations:
- Operation 1: Given , add to .
- Operation 2: Given , choose a non-empty subsequence from . For all possible choices, compute the sum of variances of the chosen subsequences. Output the answer modulo .
The variance of a sequence is defined as follows. Let , then the variance is .
Input Format
The first line contains two integers .
The next lines describe the operations. Each line contains either four integers or three integers , representing an operation of the first type or the second type. It is guaranteed that .
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 of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For another of the testdata, , and it is guaranteed that all operations of the first type come first, followed by operations of the second type.
For of the testdata, .
For of the testdata, .
For the first query in the first testdata, the sequence is . Among all subsequences, only , , and have non-zero variance, which are respectively. Their total sum is .
Translated by ChatGPT 5