#P11373. 「CZOI-R2」天平

    ID: 12268 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>平衡树数论O2优化最大公约数 gcd差分洛谷比赛

「CZOI-R2」天平

Problem Description

You have nn weight groups, numbered from 11 to nn. In the ii-th weight group, all weights have the same positive integer mass aia_i, and the number of weights in each weight group is unlimited.

There are qq operations:

  • I x v: Insert a new weight group after the xx-th weight group, where the mass of a single weight in this new group is vv. When x=0x=0, it means inserting at the very front.
  • D x: Delete the xx-th weight group.
  • A l r v: Add vv to the mass of the weights in all weight groups from ll to rr.
  • Q l r v: Determine whether it is possible to measure mass vv using weights from weight groups ll to rr. You may use any number of weights from each group, including zero.

For operations I and D, after the operation, the indices and the value of nn will change automatically.

A set of weights can measure mass vv if and only if there exists a way to place these weights on the two sides of the balance scale such that placing one object of mass vv on one side can make the scale balance.

Input Format

The first line contains 22 integers n,qn,q.

The second line contains nn integers, where the ii-th integer is aia_i.

The next qq lines each describe one operation.

Output Format

For each Q operation, output one line YES or NO, indicating whether mass vv can be measured.

5 5
1 10 8 4 2
I 2 1
A 1 4 4
A 2 4 4
D 5
Q 1 4 4
YES
10 10
2 2 1 4 2 10 8 7 10 6
Q 5 6 1
Q 5 7 7
I 5 1
Q 4 5 3
Q 2 9 2
A 3 5 1
Q 7 8 5
D 7
A 3 9 7
Q 3 7 6
NO
NO
NO
YES
NO
YES

Hint

[Sample Explanation]

For sample group 11, in the end there are 55 weight groups, with masses 5,18,9,16,25,18,9,16,2 respectively. Put 11 weight from weight group 1 on the left side of the balance, and put 11 weight from weight group 3 on the right side, then you can measure mass 44.

[Constraints]

This problem uses bundled testdata.

Let m1m_1 be the minimum value of aia_i and vv over all moments, and let m2m_2 be the maximum value of aia_i and vv over all moments.

  • Subtask #1 (5 pts5\text{ pts}): 1n,q101\le n,q\le 10, 1m1m2501\le m_1\le m_2 \le50.
  • Subtask #2 (15 pts15\text{ pts}): 1n,q4×1021\le n,q\le 4\times10^2.
  • Subtask #3 (20 pts20\text{ pts}): There are no I operations and no D operations.
  • Subtask #4 (60 pts60\text{ pts}): No special properties.

For 100%100\% of the data, 1n,q1051\le n,q\le 10^5, 1m1m210181\le m_1\le m_2\le 10^{18}. It is guaranteed that all operations are valid, and at any moment there is at least one weight group.

Translated by ChatGPT 5