#P4641. [BJWC2008] 序列

[BJWC2008] 序列

Description

For a sequence {an}\{a_n\} of length NN (ai[0,2161])(a_i \in [0, 2^{16} - 1]), perform the following two types of operations, for a total of MM operations:

  1. A x (x0)(x \ge 0): ai=ai+xmod216a_i = a_i + x \mod 2^{16}.

  2. Q i: Query the value of $Card\{k \mid (a_k\;\&\;2^i) > 0, 1 \le k \le N, k \in \mathbb{Z}\}$.

Here, the &\& operator is the same as & in C/C++ or and in Pascal.

Given the initial sequence and the list of operations, simulate the process and compute the sum of the results of all Q operations.

Input Format

The first line contains two integers N,MN, M separated by spaces, representing NN and MM.

The next NN lines each contain one integer, representing the initial sequence.

The next MM lines each describe one operation, in the format stated in the description.

Output Format

Output one integer, representing the sum of the results of all Q operations.

3 5
1
2
4
Q 1
Q 2
A 1
Q 1
Q 2
5

Hint

The initial sequence is 1  2  41\;2\;4.

Q 1: Only a2=2a_2 = 2 satisfies (ak  &  2i)>0(a_k\;\&\;2^i) > 0, so the result of this Q operation is 11.

Q 2: Only a3=4a_3 = 4 satisfies (ak  &  2i)>0(a_k\;\&\;2^i) > 0, so the result of this Q operation is 11.

A 1: The original sequence becomes 2  3  52\;3\;5.

Q 1: Only a1=2,a2=3a_1 = 2, a_2 = 3 satisfy (ak  &  2i)>0(a_k\;\&\;2^i) > 0, so the result of this Q operation is 22.

Q 2: Only a3=5a_3 = 5 satisfies (ak  &  2i)>0(a_k\;\&\;2^i) > 0, so the result of this Q operation is 11.

1+1+2+1=51 + 1 + 2 + 1 = 5, so the final result is 55.

Constraints:

30%30\% of the testdata satisfy 1N100,1M10001 \le N \le 100, 1 \le M \le 1000.

100%100\% of the testdata satisfy 1N,M1051 \le N, M \le 10^5.

Translated by ChatGPT 5