#P9711. [KMOI R1] 五五五五(Hard)
[KMOI R1] 五五五五(Hard)
Background
“Things can be inferred from each other, and each has its place. So although branches split, they share the same trunk. This only reveals one end of it. Also, when analyzing principles through words and explaining structures with diagrams, it may be concise yet complete, clear yet not verbose. Readers will understand more than half just by thinking.” — Liu Hui.
Problem Description
Xiao Song has a sequence , where .
For , he defines as the number of consecutive trailing ’s at the end of .
For example, for the sequence , .
Xiao Song will keep performing operations on this sequence. Specifically, he will do the following operations:
-
: Change the -th number to ().
-
: Reverse the sequence . For example, becomes after reversing.
-
: Query the sequence.
-
: Query the sequence.
For each operation , output:
$$\Big(\sum\limits_{l=1}^ {n}\sum\limits_{r=l}^{n} f(l,r)\Big) \bmod 10^9+7$$For each operation , output:
Input Format
The first line contains two positive 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 or three positive integers, representing an operation.
Output Format
For each operation and operation , output the answer.
3 4
1 5 5
1 3 3
3
1 1 5
4 1 3
2
13
6 5
1 1 4 5 1 4
3
2
3
1 1 5
4 1 4
4
3
15
Hint
Explanation for Sample :
| Operation | Sequence after the operation | Answer |
|---|---|---|
Explanation for Sample :
| Operation | Sequence after the operation | Answer |
|---|---|---|
Constraints
| Test Point ID | Special Property | ||
|---|---|---|---|
Special property : There is no operation .
Special property : There is no operation .
For of the testdata: , .
, .
Translated by ChatGPT 5