#P6562. [SBCOI2020] 归家之路

    ID: 5104 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化状态压缩,状压前缀和块状链表,块状数组,分块

[SBCOI2020] 归家之路

Description

There are 2n2^n stars in the sky, numbered 0,1,,2n10,1,\ldots,2^n-1 in order. Each star has a brightness value. Initially, the brightness of star ii is aia_i.

For two positive integers a,ba,b, we define a Boolean operation aba\otimes b. If, in the binary representation of aa, every bit where aa is 11 also has the corresponding bit of bb equal to 11, then aba\otimes b is True; otherwise, it is False.
If the two numbers have different bit lengths in binary, align them to the right and pad zeros on the left. For example, for 11 and 1111 (in binary), 11 becomes 0101.

There are two types of operations on the brightness values:

  1. 11 aa bb kk. For all cc such that aca\otimes c is True and cbc\otimes b is True, add kk to the brightness of star cc.

  2. 22 aa bb. For all cc such that aca\otimes c is True and cbc\otimes b is `True$, compute the sum of the brightness values of all such stars$c$, and output the result modulo 2322^{32}.

Input Format

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

The second line contains 2n2^n integers separated by spaces, representing a0,a1,,a2n1a_0,a_1,\cdots,a_{2^n-1}.

The next qq lines each describe one operation, in the format given in the Description.

Output Format

For each operation of type 22, output one line containing the answer.

3 3
1 2 3 4 5 6 7 8
2 0 7
1 1 5 1
2 1 7
36
22

Hint

Sample Explanation

The first operation is a query. The binary representation of 00 is 000000, and the binary representation of 77 is 111111. At this time, all numbers satisfy the condition, so we take the sum of all numbers, which is 3636.

The second operation is an update. The binary representation of 11 is 001001, and the binary representation of 55 is 101101. We find that c=1,5c=1,5 satisfy the condition, with binary representations 001001 and 101101 respectively, so a1,a5a_1,a_5 change from 2,62,6 to 3,73,7.

The third operation is a query. The binary representation of 11 is 001001, and the binary representation of 77 is 111111. We find that c=1,3,5,7c=1,3,5,7 satisfy the condition, with binary representations 001001, 011011, 101101, 111111 respectively. We need the sum a1+a3+a5+a7=3+4+7+8=22a_1+a_3+a_5+a_7=3+4+7+8=22.

Constraints

This problem uses bundled testdata and has 44 subtasks.

Subtask1(1%)Subtask 1(1\%): The answers match the sample.

Subtask2(9%)Subtask 2(9\%): n12,m2×103n \le 12,m \le 2\times 10^3.

Subtask3(15%)Subtask 3(15\%): All type 22 operations occur after type 11 operations.

Subtask4(75%)Subtask 4(75\%): No additional restrictions.

For 100%100\% of the testdata, $1 \le n \le 16,1 \le m \le 2\times 10^5, 0 \le a,b \le 2^n-1,0 \le a_i,k \le 2^{32}-1$.

Friendly Reminder

To take modulo 2322^{32}, you can directly use an unsigned 32-bit integer type for computations. In c++, this is unsigned int.

That is, just let it overflow naturally and nothing will happen.

Translated by ChatGPT 5