XOR Sum 2
Time limit2sMemory limit512 MB
Process a stream of insertions and queries, printing the XOR of the K largest stored values.
- Level
Medium7 of 10
- Topics
- Trie, Bit manipulation, Binary search, Sorting
- Solved
- No attempts yet
Problem
You keep one list of numbers. The list starts empty, and you process instructions in the order given.
The instruction insert N puts the number into the list. The same number can arrive several times, and every arrival stays in the list.
The instruction print K prints the XOR sum of the largest numbers in the list. If a number is present several times, each copy counts as its own element. If the list holds fewer than numbers, print the XOR sum of every number in the list, and if the list is empty, print 0.
The XOR sum of a group of numbers is the result of XOR-ing all of them. Most languages compute the XOR of two integers with the ^ operator, and Haskell uses xor. XOR has the property that implies and .
Input
The first line contains the number of test cases (). The first line of each test case contains the number of instructions (), and the next lines contain one instruction each.
Each instruction has one of the two forms below.
insert N
print K
is a non-negative integer smaller than , and is a positive integer smaller than .
Output
For every print instruction, print the answer on its own line. The list starts empty again for each test case.