#P3934. [Ynoi Easy Round 2016] 炸脖龙 I

    ID: 2875 远端评测题 2500ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016线段树树状数组O2优化枚举,暴力洛谷月赛Ynoi

[Ynoi Easy Round 2016] 炸脖龙 I

Description

You are playing a galgame, but you find this gal confusing and give up. So you start writing a data structure problem instead.

Given a sequence of length nn, there are mm operations. Each operation is one of the following:

  1. Add xx to the range [l,r][l, r].
  2. For the range [l,r][l, r], query
a[l]a[l+1]a[l+2]a[r]modp.a[l]^{a[l+1]^{a[l+2]^{\dots ^{a[r]}}}} \mod p.

Input Format

The first line contains two integers n,mn, m, the length of the sequence and the number of operations.

The second line contains nn integers, the sequence.

Each of the next mm lines is one of the following two operations.

  • 1 l r x1\ l\ r\ x: add xx to the range [l,r][l, r].
  • 2 l r p2\ l\ r\ p: query the range [l,r][l, r] with modulus pp.

Output Format

For each query, output one number as the answer.

6 4
1 2 3 4 5 6
2 1 2 10000007
2 2 3 5
1 1 4 1
2 2 4 10

1
3
1
5 5
2 3 3 3 3
1 1 1 530739835
2 1 1 8356089
2 1 4 5496738
1 1 2 66050181
1 2 4 138625417

4306230
697527

Hint

Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477.

Constraints:

  • For 100% of the testdata, n,m500000n, m \le 500000, each number in the sequence is in [1,2109][1, 2 \cdot 10^9], p2107p \le 2 \cdot 10^7, and each added xx is in [0,2109][0, 2 \cdot 10^9].

There are 10 sets of testdata.

Translated by ChatGPT 5