This page is still under construction.

Parts of this page are still being built. What you see may change.

The Jet-Black Wings

Time limit3sMemory limit512 MB

Summary
Maintain a multiset under global XOR updates and queries asking for the sum of the K smallest elements.
Level

Hard8 of 10

Topics
Trie, Bit manipulation, Divide and conquer, Implementation
Solved
No attempts yet

Problem

"AHHHHHHHHH..."

Eddy, who calls himself the Jet-Black Wings, was fighting an evil organization named Dark Reunion. Then he woke up with a start. It was a dream.

"I must be more powerful." Eddy said to himself.

Eddy trains often to become a powerful fighter. During his training he collected NN magic stones. The ii-th stone holds AiA_i units of dark force. Eddy takes QQ turns, and on each turn he chooses one of two actions.

  • 1 X: Use XX units of dark force on every magic stone. The dark force of each stone becomes the bitwise exclusive or of its current value and XX, so a stone holding AiA_i comes to hold Ai⊕XA_i \oplus X.
  • 2 K: Sort all magic stones by dark force in increasing order, then add up the dark force of the first KK stones. This turn does not change the dark force of any stone.

Help Eddy check whether his numbers are right.

x⊕yx \oplus y is the result of applying the bitwise exclusive or operation to the integers xx and yy. Every modern programming language provides this operation. C++ and Java write it as ^, and Pascal writes it as xor.

Input

The first line contains a single integer TT, the number of test cases.

The first line of each test case contains two integers NN and QQ, the number of magic stones and the number of instructions.

The second line of each test case contains NN integers A1,A2,…,ANA_1, A_2, \dots, A_N, where AiA_i is the dark force of the ii-th magic stone.

Each of the following QQ lines contains one instruction, either 1 X or 2 K.

You may assume:

  • T≤1000T \le 1000
  • 1≤N,Q≤1000001 \le N, Q \le 100000
  • 0≤Ai,X<2310 \le A_i, X < 2^{31}
  • 1≤K≤N1 \le K \le N
  • At most 5 test cases have N+Q>200N + Q > 200.

Output

For each 2 K instruction, print on its own line the sum of the dark force of the first KK magic stones after sorting.

Examples7

  1. Example 1

    Input
    1
    3 6
    4 8 3
    1 3
    1 1
    2 3
    1 2
    2 2
    2 1
    
    Expected output
    17
    7
    3
    
  2. Example 2

    Input
    1
    1 4
    2147483647
    2 1
    1 2147483647
    2 1
    2 1
    
    Expected output
    2147483647
    0
    0
    
  3. Example 3

    Input
    1
    5 6
    0 0 0 0 0
    2 5
    1 1073741824
    2 3
    2 5
    1 1073741824
    2 5
    
    Expected output
    0
    3221225472
    5368709120
    0
    
  4. Example 4

    Input
    1
    100 5
    2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646 2147483646
    2 100
    1 1
    2 100
    1 2147483647
    2 100
    
    Expected output
    214748364650
    214748364650
    50
    
  5. Example 5

    Input
    1
    6 7
    5 5 5 9 9 1
    2 4
    1 4
    2 4
    2 1
    2 6
    1 4
    2 3
    
    Expected output
    16
    8
    1
    34
    11
    
  6. Example 6

    Input
    3
    2 3
    1 2
    2 2
    1 3
    2 1
    4 4
    7 7 0 1
    2 4
    1 6
    2 2
    2 4
    1 2
    0
    2 1
    1 5
    
    Expected output
    3
    1
    15
    2
    15
    0
    
  7. Example 7

    Input
    1
    5 8
    10 20 30 40 50
    2 5
    1 123456789
    2 5
    2 2
    1 123456789
    2 5
    2 2
    2 3
    
    Expected output
    150
    617283983
    246913548
    150
    30
    60