显示原始代码
#include <bits/stdc++.h>
using namespace std;
struct tree {
tree() {
cnt = 0;
t0 = nullptr;
t1 = nullptr;
}
int cnt;
tree* t0;
tree* t1;
};
tree T = tree();
int sum1[32];
void update(tree* root, int depth) {
if (root->t1 != nullptr) {
update(root->t1, depth + 1);
}
if (root->t0 != nullptr) {
sum1[depth] += root->t0->cnt;
}
if (root->t1 != nullptr) {
sum1[depth] -= root->t1->cnt;
}
swap(root->t0, root->t1);
}
void tInsert(int x) {
tree* t = &T;
tree* nt;
for (int i = 0; i < 31; i++) {
int k = (x >> i) & 1;
if (k == 0) {
nt = t->t0;
if (nt == nullptr) {
nt = new tree();
t->t0 = nt;
}
} else {
nt = t->t1;
if (nt == nullptr) {
nt = new tree();
t->t1 = nt;
}
}
t->cnt++;
if (k == 1)
sum1[i]++;
t = nt;
}
}
int query() {
int res = 0;
for (int i = 0; i <= 31; i++) {
res |= ((sum1[i] & 1) << i);
}
return res;
}
int main() {
int n;
int opt;
memset(sum1, 0, sizeof(sum1));
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &opt);
if (opt == 1) {
update(&T, 0);
} else {
int tem;
scanf("%d", &tem);
tInsert(tem);
}
printf("%d\n", query());
}
}