Mass XOR queries - MarisaOJ: Marisa Online Judge

Mass XOR queries

Time limit: 1000 ms
Memory limit: 512 MB
You are given an initially empty **multiset** $S$, and you need to perform four types of queries on it: - $(1, x)$: Insert the integer $x$ into $S$. - $(2, x)$: Remove one occurrence of $x$ from $S$. It is guaranteed that $x$ appears in $S$. - $(3, x)$: For each element $p$ in $S$, perform the bitwise XOR operation with $x$ (.i.e $p$ to $p \oplus x$). - $(4, k)$: Find the $k$-th smallest element of $S$ when it is sorted in non-decreasing order. It is guaranteed that $k \le |S|$, where $|S|$ denotes the size of the multiset. Your task is to implement a solution that can efficiently perform these operations and find the answer for each query of type $4$. ### Input - The first line contains an integer $q$. - The next $q$ lines, each line contains 2 integers, a query. ### Output - Print the answer for each query of type $4$. ### Constraints - $1 \le q \le 10^5$. - $1 \le x \le 10^5$. - $1 \le k$. ### Example Input: ``` 5 1 1 2 1 1 4 1 5 4 2 ``` Output: ``` 5 ```