The Jet-Black Wings
Time limit3sMemory limit512 MB
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 magic stones. The -th stone holds units of dark force. Eddy takes turns, and on each turn he chooses one of two actions.
1 X: Use units of dark force on every magic stone. The dark force of each stone becomes the bitwise exclusive or of its current value and , so a stone holding comes to hold .2 K: Sort all magic stones by dark force in increasing order, then add up the dark force of the first stones. This turn does not change the dark force of any stone.
Help Eddy check whether his numbers are right.
is the result of applying the bitwise exclusive or operation to the integers and . 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 , the number of test cases.
The first line of each test case contains two integers and , the number of magic stones and the number of instructions.
The second line of each test case contains integers , where is the dark force of the -th magic stone.
Each of the following lines contains one instruction, either 1 X or 2 K.
You may assume:
- At most 5 test cases have .
Output
For each 2 K instruction, print on its own line the sum of the dark force of the first magic stones after sorting.