#include #include using namespace std; // ----- TYPES ----- typedef long long ll; typedef pair pii; typedef vector vi; // ----- FILE IO ----- #define STDIN(filename) freopen(filename, "r", stdin) #define STDOUT(filename) freopen(filename, "w", stdout) #define FASTIO cin.tie(0)->sync_with_stdio(0) #define STDIO(filename) \ FASTIO; \ string filenamee(filename); \ STDIN((filenamee + ".in").c_str()); \ STDOUT((filenamee + ".out").c_str()) #define NL '\n' #define CM ", " #define SP " " // ----- FOR LOOPS ----- #define F(i, L, R) for (int i = L; i < R; i++) #define FE(i, L, R) for (int i = L; i <= R; i++) #define FD(i, L, R) for (int i = L; i > R; i--) #define FDE(i, L, R) for (int i = L; i >= R; i--) // ----- WEZ ----- #define takeI(n) \ int n; \ cin >> n #define takeII(n, m) \ int n, m; \ cin >> n >> m #define takeIII(n, m, k) \ int n, m, k; \ cin >> n >> m >> k #define takeL(n) \ ll n; \ cin >> n #define takeS(s) \ string s; \ cin >> s #define takeV(v, n) \ vi v(n); \ for (auto &x : v) \ cin >> x #define takeVL(v, n) \ vector v(n); \ for (auto &x : v) \ cin >> x #define whileZ \ takeI(T); \ while (T--) // // ----- MAX MIN ----- #define REMAX(a, b) (a) = max((a), (b)) #define REMIN(a, b) (a) = min((a), (b)) // ----- PAIRS ----- #define fi first #define se second // ----- OUTPUT ----- #define YESNO(b) cout << ((b) ? "YES" : "NO") << NL // ----- DEBUG ----- #define DBG(vari) cerr << #vari << " = " << (vari) << endl #define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl #define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') #define printV(a) printA(a, 0, SZ(a) - 1) // ----- STL DS #define ALL(c) (c).begin(), (c).end() #define SZ(c) ((int)(c).size()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(ALL(c), greater<>()) #define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) #define pb push_back // struct TrieNode { // bool end = false; // TrieNode* children[2]; // }; // // void insert_into_trie(TrieNode* node, uint x) { // // If we have exhausted x, this current node must be finished // // For example if we have 0 // if (!x) { // node->end = true; // return; // } // // // Get last digit of x // bool last_digit = x & 1; // // // Ensure child of this type exists // if (!node->children[last_digit]) { // node->children[last_digit] = new TrieNode; // } // // insert_into_trie(node->children[last_digit], x >> 1); // } // // bool remove_from_trie(TrieNode* node, uint x) { // if (!x) { // node->end = false; // } else { // bool last_digit = x & 1; // if (node->children[last_digit] && remove_from_trie(node->children[last_digit], x >> 1)) { // node->children[last_digit] = nullptr; // }; // } // // // if (!node->children[0] && !node->children[1] && !node->end) { // delete node; // return true; // } // return false; // } // // int find_min_from_trie(TrieNode* node, uint x) { // if (!x) { // return 0; // } // // bool last_digit = x & 1; // // if (node->children[last_digit]) { // return (find_min_from_trie(node->children[last_digit], x >> 1)) ^ (last_digit << 1); // } else if (node->children[!last_digit]) { // return (find_min_from_trie(node->children[!last_digit], x >> 1)) ^ (!last_digit << 1); // } else { // return 0; // } // } struct Trie { int cnt = 0; Trie* ch[2] = {}; }; void insert(Trie* root, int x) { Trie* cur = root; for (int i = 30; i >= 0; i--) { bool digit = x & (1 << i); if (!cur->ch[digit]) { cur->ch[digit] = new Trie; } cur->ch[digit]->cnt++; cur = cur->ch[digit]; } } void remove(Trie* root, int x) { Trie* cur = root; for (int i = 30; i >= 0; i--) { bool digit = x & (1 << i); cur->ch[digit]->cnt--; cur = cur->ch[digit]; } } int query(Trie* root, int x) { Trie* cur = root; int res = 0; for (int i = 30; i >= 0; i--) { bool digit = x & (1 << i); if (cur->ch[digit] && cur->ch[digit]->cnt > 0) { cur = cur->ch[digit]; } else { cur = cur->ch[!digit]; res += 1 << i; } } return res; } int main() { FASTIO; takeI(t); Trie* root = new Trie; unordered_set s; while (t--) { takeI(op); uint x; cin >> x; if (op == 0) { // Insert into trie if (!s.count(x)) { s.insert(x); insert(root, x); } } else if (op == 1) { // Remove from trie if (s.count(x)) { s.erase(x); remove(root, x); } } else { // Query trie cout << query(root, x) << NL; } } }