Guess the Data Structure
Time limit5sMemory limit256 MB
Maintain an array that supports appending values, range sum queries, xoring every element with x, and sorting the array.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Trie, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
You are given an array of integers, numbered from 1 to . Process queries of the following kinds:
- Append integer to the end of the array .
- Output the value of ().
- Replace each element with , where is bitwise XOR.
- Sort the array .
Implement a data structure that processes these queries.
Input
The first line contains (), the initial size of . The second line contains integers (). The third line contains (), the number of queries. Each of the next lines is one query in one of these formats: 1 , 2 , 3 , or 4.
For queries of types 1 and 3, . For queries of type 2, and are within the bounds of the array. Each test case has at least one query of type 2.
Output
For each query of type 2, output its sum on a separate line.