#include #include int cmp_int_2d (const void *a, const void *b) { int *a_ = (int *)a; int *b_ = (int *)b; if (a_[0] < b_[0]) { return -1; } if (a_[0] > b_[0]) { return 1; } if (a_[1] < b_[1]) { return -1; } if (a_[1] > b_[1]) { return 1; } return 0; } int main () { int q = 0; int t[400000] = {}; int x[400000] = {}; int res = 0; int xit[400000][3] = {}; int cnt[30] = {}; int num = 0; res = scanf("%d", &q); for (int i = 0; i < q; i++) { res = scanf("%d", t+i); if (t[i] == 1 || t[i] == 2) { res = scanf("%d", x+i); } else { x[i] = -1; } xit[i][0] = x[i]; xit[i][1] = i; xit[i][2] = t[i]; } qsort(xit, q, sizeof(int)*3, cmp_int_2d); for (int i = 0; i < q; i++) { if (t[i] == 1) { int idx[2] = { -1, q-1 }; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (xit[nxt][0] < x[i] || (xit[nxt][0] == x[i] && xit[nxt][1] < i)) { idx[0] = nxt; } else { idx[1] = nxt; } } if (idx[0] < 0 || xit[idx[0]][0] != x[i] || xit[idx[0]][2] == 2) { for (int j = 0; j < 30; j++) { if ((x[i]&(1< 0) { cnt[j]++; } } num++; } } else if (t[i] == 2) { int idx[2] = { -1, q-1 }; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (xit[nxt][0] < x[i] || (xit[nxt][0] == x[i] && xit[nxt][1] < i)) { idx[0] = nxt; } else { idx[1] = nxt; } } if (idx[0] >= 0 && xit[idx[0]][0] == x[i] && xit[idx[0]][2] == 1) { for (int j = 0; j < 30; j++) { if ((x[i]&(1< 0) { cnt[j]--; } } num--; } } else { int ans = 0; for (int j = 0; j < 30; j++) { if (cnt[j] == num) { ans += (1< 0) { printf("%d\n", ans); } else { printf("-1\n"); } } } return 0; }