#P2023. [AHOI2009] 维护序列

[AHOI2009] 维护序列

Description

There is a sequence of length nn, {ai}\{a_i\}, with the following three types of operations:

  1. Format 1 t g c: set all aia_i with tigt \le i \le g to ai×ca_i \times c.
  2. Format 2 t g c: set all aia_i with tigt \le i \le g to ai+ca_i + c.
  3. Format 3 t g: query the sum of all aia_i with tigt \le i \le g. Since the answer may be large, you only need to output this sum modulo pp.

Input Format

The first line contains two integers nn and pp.

The second line contains nn non-negative integers, representing the sequence {ai}\{a_i\}.

The third line contains an integer mm, the total number of operations.

From the fourth line on, each line describes one operation. In the same line, adjacent numbers are separated by a single space, and there are no extra spaces at the beginning or end.

Output Format

For each operation of type 3, in the order they appear in the input, output one integer per line representing the query result.

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

Hint

Explanation for Sample Input/Output 1

  • Initially, the sequence is {1,2,3,4,5,6,7}\{1,2,3,4,5,6,7\}.
  • After the 1st operation, the sequence becomes {1,10,15,20,25,6,7}\{1,10,15,20,25,6,7\}.
  • For the 2nd operation, the sum is 10+15+20=4510+15+20=45, and 45mod43=245 \bmod 43 = 2.
  • After the 3rd operation, the sequence becomes {1,10,24,29,34,15,16}\{1,10,24,29,34,15,16\}.
  • For the 4th operation, the sum is 1+10+24=351+10+24=35, and 35mod43=3535 \bmod 43 = 35.
  • For the 5th operation, the sum is 29+34+15+16=9429+34+15+16=94, and 94mod43=894 \bmod 43 = 8.

Constraints

The testdata scale is as follows:

Data point ID 1 2 3 4 5 6 7 8 9,10
n=n= 1010 10001000 1000010000 6000060000 7000070000 8000080000 9000090000 100000100000
m=m=

For all test points, it is guaranteed that 0p,ai,c1090 \le p, a_i, c \le 10^9, 1tgn1 \le t \le g \le n.

Translated by ChatGPT 5