#P7497. 四方喝彩
四方喝彩
Description
Mike has a total of new acts, and the thrill value of the -th act is .
Next, Mike can apply several operations to modify the thrill values:
-
Mike uses an ice ball: for all , the thrill value of the -th act increases by .
-
Mike uses an earth ball: for all , the thrill value of the -th act is multiplied by .
-
Mike uses a fire ball: for all , the thrill value of the -th act will not be affected by ice balls and earth balls in the next operations. The fire ball effect will not be overwritten.
Of course, the audience is also curious about the thrill values of each act, so during the operations you need to help Mike answer: for all , what is the sum of the thrill values of the -th acts. The audience also does not want the thrill values to become too large, so you need to take the result modulo .
Brief statement:
You are given an array of length . You need to support the following operations:
l r x: for all , increase by .l r x: for all , multiply by .l r x: for all , during the next operations, will be locked and will not be affected by operation 1 and operation 2 (let this operation be the -th operation, then in the -th operations, all operation 1 and operation 2 will have no effect on the interval ). Existing lock effects will not be overwritten (that is, suppose in the 3rd operation there is an operation 3 that locks some position for 5 operations, and in the 5th operation it locks the same position for 2 operations, then in fact this position will be locked from the 4th operation through the 8th operation). (Intuitively, a later shorter lock will not cancel an earlier longer lock.)l r: query , modulo .
Input Format
The first line contains two positive integers , representing the array length and the number of operations.
The second line contains integers , representing the array .
The next lines each contain three integers , representing the operation type and the range . If , there is also an integer , representing the value for this operation.
Output Format
For every operation 4, output one integer per line, representing the result modulo .
5 5
1 5 4 3 6
1 2 4 3
3 1 2 2
4 2 5
2 2 3 4
4 1 3
27
37
10 12
4 2 1 5 10 3 2 4 6 7
2 3 7 4
1 2 9 5
3 2 4 5
3 4 7 2
4 3 9
1 1 8 2
2 4 5 2
3 6 8 2
4 2 3
1 2 10 6
2 7 9 3
4 1 10
129
16
314
Hint
Explanation for Sample 1
Initially, the array is .
- Perform the 1st operation, and the array becomes .
- Perform the 2nd operation, and the array remains unchanged.
- Perform the 3rd operation, and the query result is .
- Perform the 4th operation: since was locked in the 2nd operation and has not been unlocked yet, this operation only affects , and the array becomes .
- Perform the 5th operation, and the query result is .
Constraints
This problem uses bundled testdata.
- Subtask 1 ( ): .
- Subtask 2 ( ): no operation 3.
- Subtask 3 ( ): for all operation 4, it is guaranteed that .
- Subtask 4 ( ): no special restrictions.
For all testdata, $1\leq n,m\leq 2\times 10^5,0\leq a_i<10^9+7,1\leq l\leq r\leq n$. For all operation 1 and operation 2, it is guaranteed that . For all operation 3, let it be the -th operation, and it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号