#P12829. 「DLESS-2」XOR and Inversion

    ID: 12381 远端评测题 2000ms 128~1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>O2优化分治虚树字典树 Trie线段树合并洛谷比赛

「DLESS-2」XOR and Inversion

Description

You are given a permutation pp of integers from 00 to 2n12^n-1. You need to perform qq operations. Each operation is one of the following two types:

  • 1 x: Every element pip_i in the permutation is replaced by pixp_i \oplus x.
  • 2 x: The permutation is reordered. For every ii, the new element at index ii is the element that was previously at index ixi \oplus x.

Here, \oplus denotes the bitwise XOR operation. The effects of the operations are cumulative.

After each operation, you need to find the total number of inversions in the current permutation.

Input Format

The input consists of multiple test cases. The first line contains a single positive integer TT, representing the number of test cases.

For each test case:

The first line contains two integers nn and qq.

The second line contains 2n2^n integers, representing the permutation pp.

The next qq lines each contain two integers, representing an operation in the format described above.

Output Format

After each operation, output a single line with a single integer, which is the answer.

3
3 2
7 6 3 2 5 1 0 4 
1 1
1 0
2 4
1 3 0 2 
1 2
1 0
1 1
2 3
2 3
0 2 1 3 
2 1
1 2
2 3
18
18
5
5
3
3
3
1
5

3
2 2
1 3 2 0 
2 1
2 1
2 2
1 0 3 2 
2 2
2 0
3 5
2 5 3 1 7 0 6 4 
1 4
2 0
2 0
1 5
2 5
4
4
6
6
21
21
21
11
19
1
5 9
21 26 25 9 11 15 4 5 20 14 3 10 23 27 19 7 18 6 29 28 16 17 12 30 22 8 24 2 1 31 0 13 
2 21
1 16
1 15
2 0
2 10
2 24
2 11
1 30
1 21
269
225
227
227
259
257
267
223
275
1
0 4
0
1 0
2 0
2 0
1 0
0
0
0
0

Hint

For all test data, it is guaranteed that:

  • 1T1051\le T\le 10^5
  • 12n,2n2201\le 2^n, \sum 2^n\le 2^{20}
  • 1q,q1061\le q, \sum q\le 10^6
  • 0x<2n0\le x<2^n

This problem uses bundled tests. The subtasks are described as follows:

Subtask 2n\sum 2^n\le q\sum q\le Special Properties Points
11 292^9 500500 None 55
22 2112^{11} 20002000 1010
33 2152^{15} 3×1053\times10^5 1515
44 2182^{18} A 55
55 B
66 None 1010
77 2202^{20} 10610^6 A 55
88 B 1010
99 3×1053\times10^5 None 1515
1010 10610^6 1010
1111

The memory limit for Subtask 11 is 128MB; for all other subtasks, it is 1GB.

Special Property A: Only type 1 operations are given.

Special Property B: Only type 2 operations are given.