XOR Game
Time limit3sMemory limit512 MB
Given an array with point updates, answer range queries for the index whose XOR with x is smallest or largest, breaking ties by the smallest index.
- Level
Medium6 of 10
- Topics
- Segment tree, Trie, Bit manipulation
- Solved
- No attempts yet
Problem
Jaehyeon and Junhyeok's favorite game these days is the XOR game.
In the XOR game, given an array , the following queries are processed.
- 1 : Among all satisfying , choose the whose XOR with is the smallest, and print that . If several such exist, print the smallest one.
- 2 : Under the same conditions, choose the whose XOR with is the largest, and print that . If several such exist, print the smallest one.
- 3 : Change to .
Write a program that runs the XOR game for Jaehyeon and Junhyeok.
Input
The first line contains the size of the initial array.
The second line contains the elements of the initial array.
The third line contains the number of queries .
Each of the next lines contains a query. , ,
Output
For each query of type 1 or 2, print the answer on its own line, in the order the queries are given.