#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 nn, denoted as a1,a2,,ana_1,a_2,\cdots ,a_n. 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 PP.

Input Format

The first line contains two integers nn and PP;

The second line contains nn non-negative integers, from left to right as a1,a2,,ana_1,a_2,\cdots ,a_n;

The third line contains an integer MM, 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 11: 1 t g c, which means changing all aia_i satisfying tigt\le i\le g to ai×ca_i\times c;
  • Operation 22: 2 t g c, which means adding cc to all aia_i satisfying tigt\le i\le g;
  • Operation 33: 3 t g, which queries the sum of all aia_i satisfying tigt\le i\le g modulo PP.

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 33, 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 {1,2,3,4,5,6,7}\{1,2,3,4,5,6,7\};

After the first operation, the sequence becomes {1,10,15,20,25,6,7}\{1,10,15,20,25,6,7\};

For the second operation, the sum is 10+15+20=4510+15+20=45, and the result modulo 4343 is 22;

After the third operation, the sequence becomes {1,10,24,29,34,15,16}\{1,10,24,29,34,15,16\};

For the fourth operation, the sum is 1+10+24=351+10+24=35, and the result modulo 4343 is 3535;

For the fifth operation, the sum is 29+34+15+16=9429+34+15+16=94, and the result modulo 4343 is 88.

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 11 2,32,3 44 55 66 77 88 9,109,10
n=n= 1010 10310^3 10410^4 6×1046\times 10^4 7×1047\times 10^4 8×1048\times 10^4 9×1049\times 10^4 10510^5
M=M=