显示原始代码
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXM = 31;
const int MAXN = 2 * 1e5;
int n;
int bcnt[MAXM + 5], tcnt = 1;
struct Node {
int cnt, nxt[2];
} T[MAXN * MAXM + 5];
void Insert(int u, int x, int d) {
if (d > MAXM)
return;
T[u].cnt++;
if (x & 1)
bcnt[d]++;
if (!T[u].nxt[(x >> 1) & 1])
T[u].nxt[(x >> 1) & 1] = ++tcnt;
Insert(T[u].nxt[(x >> 1) & 1], x >> 1, d + 1);
return;
}
void Add(int u, int d) {
if (d > MAXM)
return;
if (T[u].nxt[1])
Add(T[u].nxt[1], d + 1);
if (T[u].nxt[0])
bcnt[d] += T[T[u].nxt[0]].cnt;
if (T[u].nxt[1])
bcnt[d] -= T[T[u].nxt[1]].cnt;
swap(T[u].nxt[0], T[u].nxt[1]);
}
inline int Query() {
int res = 0;
for (int i = 0; i < MAXM; ++i) res |= (bcnt[i] & 1) << i;
return res;
}
int main() {
scanf("%d", &n);
int opt, x;
while (n--) {
scanf("%d", &opt);
if (opt == 1) {
if (T[1].cnt)
Add(1, 1);
bcnt[0] += T[0].cnt - T[1].cnt;
swap(T[0], T[1]);
} else {
scanf("%d", &x);
Insert(x & 1, x, 0);
}
printf("%d\n", Query());
}
return 0;
}