#P3747. [六省联考 2017] 相逢是问候

    ID: 1300 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学2017线段树各省省选O2优化欧拉公式素数判断,质数,筛法

[六省联考 2017] 相逢是问候

Description

Informatik verbindet dich und mich.
Information connects you and me.

Mr. B wants to maintain an array of length nn, whose indices are the positive integers from 11 to nn.

There are mm operations, of two types:

  • 0 l r means: for each number aia_i among the ll-th to the rr-th numbers (al,al+1...ara_l,a_{l+1} ...a_r), replace aia_i with caic^{a_i}, i.e., assign ai=caia_i = c^{a_i}, where cc is a given constant in the input.

  • 1 l r asks for the sum of the ll-th to the rr-th numbers, i.e., output i=lrai\sum_{i=l}^{r} a_i.

Because the result can be very large, you only need to output the result mod p\bmod \space p.

Input Format

The first line contains four integers n,m,p,cn, m, p, c, whose meanings are given in the problem statement.
The next line contains nn integers, the initial values of the array aa.
The next mm lines each contain three integers; the first integer indicates the type of operation.

  • If it is 0, this is an update operation with parameters l,rl, r.
  • If it is 1, this is a query operation with parameters l,rl, r.

Output Format

For each query operation, output one line with a single integer: the answer mod p\bmod \space p.

4 4 7 2
1 2 3 4
0 1 4
1 2 4
0 1 4
1 1 3
0
3
1 40 19910626 2
0
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
0 1 1
1 1 1
1
2
4
16
65536
11418102
18325590
13700558
13700558
13700558
13700558
13700558
13700558
13700558
13700558
13700558
13700558
13700558
13700558
13700558

Hint

Constraints

  • For 0%0\% of the test points, identical to the sample.
  • For another 10%10\% of the test points, there are no updates.
  • For another 20%20\% of the test points, each update modifies only one position (i.e., l=rl = r), and each position is updated at most once.
  • For another 10%10\% of the test points, p=2p = 2.
  • For another 10%10\% of the test points, p=3p = 3.
  • For another 10%10\% of the test points, p=4p = 4.
  • For another 20%20\% of the test points, 1n,m1001\le n, m \le 100.
  • For 100%100\% of the test points, 1n,m5×1041\le n, m \le 5\times 10^4, 1p1081 \le p \le 10^8, 0<c<p0< c < p, 0ai<p0 \le a_i < p.

Translated by ChatGPT 5