#P10408. 「SMOI-R1」Apple

「SMOI-R1」Apple

Background

To filter out incorrect algorithms, we changed the time limit to 680 ms.

Problem Description

LAR has 2n2^n apples. The apples are numbered from 00 to 2n12^n - 1. The value of the apple with number ii is viv_i.

If AorB=AA \operatorname{or} B = A, then we say that AA contains BB (where or\operatorname{or} is bitwise OR).

Since LAR has too many apples, he does not know how to choose apples. He wants to perform some operations so that it is more convenient for him to eat apples.

There are two types of operations, for a total of qq operations:

  • 1 S1\ S: Query the sum of values of all apples whose indices are contained in SS.
  • 2 S A2\ S\ A: Change the value of the apple with index SS to AA (set vSv_S to AA).

Input Format

The first line contains two integers nn and qq, where qq is the number of operations.

The second line contains 2n2^n numbers. The ii-th number represents the value of vi1v_{i-1}.

The next qq lines each describe one operation that LAR will perform, as detailed above.

Output Format

For each operation of type 11, output one number, which is the answer to the query.

2 5
1 2 3 2
1 2
2 0 4
1 2
2 3 1
1 3
4
7
10

Hint

Sample Explanation

Initially, v=[1,2,3,2]v = [1,2,3,2].

In the first operation, we query the sum of values of all apples whose indices are contained in 22. The numbers contained in 22 are 0,20,2, so the answer is v0+v2=4v_0 + v_2 = 4.

In the second operation, we change v0v_0 to 44, so now v=[4,2,3,2]v = [4,2,3,2].

In the third operation, we query the sum of values of all apples whose indices are contained in 22. The numbers contained in 22 are 0,20,2, so the answer is v0+v2=7v_0 + v_2 = 7.

In the fourth operation, we change v3v_3 to 11, so now v=[4,2,3,1]v = [4,2,3,1].

In the fifth operation, we query the sum of values of all apples whose indices are contained in 33. The numbers contained in 33 are 0,1,2,30,1,2,3, so the answer is v0+v1+v2+v3=10v_0 + v_1 + v_2 + v_3 = 10.

Constraints

This problem uses bundled testdata.

Subtask ID nn \le qq \le Special Property Score
11 1010 10410^4 None 1010
22 1616 3×1053 \times 10^5 2020
33 2020 Only operation 1 1010
44 10510^5 None 2020
55 3×1053 \times 10^5 4040

For 100%100\% of the testdata, it is guaranteed that 1n201 \le n \le 20, 1q3×1051 \le q \le 3 \times 10^5, and 0vi23110 \le v_i \le 2^{31} - 1.

Hint: The input size of this problem is large, so please use fast input. Please pay attention to the constant factors in your code.

Translated by ChatGPT 5