#Q131. 「一本通 4.3 练习 3」维护序列
「一本通 4.3 练习 3」维护序列
Description
Original source: AHOI 2009
The teacher assigned Xiaokeke the task of maintaining a number sequence, and now Xiaokeke hopes you can help him complete it.
There is a sequence of length , denoted as . There are three types of operations:
- Multiply all numbers in a segment of the sequence by a value;
- Add a value to all numbers in a segment of the sequence;
- Query the sum of numbers in a segment of the sequence. Since the answer may be very large, you only need to output the result modulo .
Input Format
The first line contains two integers and ;
The second line contains non-negative integers, from left to right as ;
The third line contains an integer , representing the total number of operations;
Starting from the fourth line, each line describes an operation. The input operations are in the following three forms:
- Operation :
1 t g c, which means changing all satisfying to ; - Operation :
2 t g c, which means adding to all satisfying ; - Operation :
3 t g, which queries the sum of all satisfying modulo .
Adjacent numbers on the same line are separated by a single space, and there are no extra spaces at the beginning or end of each line.
Output Format
For each operation , output a single integer per line in the order they appear in the input, representing the result of the query.
Sample 1
Initially, the sequence is ;
After the first operation, the sequence becomes ;
For the second operation, the sum is , and the result modulo is ;
After the third operation, the sequence becomes ;
For the fourth operation, the sum is , and the result modulo is ;
For the fifth operation, the sum is , and the result modulo is .
7 43
1 2 3 4 5 6 7
5
1 2 5 5
3 2 4
2 3 7 9
3 1 3
3 4 7
2
35
8
Data Range and Hints
For all test data, $1\le t\le g\le n,0\le c,a_i\le 10^9,1\le P\le 10^9+7$.
The scale of the test data is as follows:
| Data ID | ||||||||
|---|---|---|---|---|---|---|---|---|