Pagini recente » Cod sursa (job #1572218) | Cod sursa (job #738454) | Cod sursa (job #1886353) | Cod sursa (job #2859450) | Cod sursa (job #1700233)
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000;
const int MAX_LOG = 31;
const int MAX_NODES = MAX_N * MAX_LOG;
const int NIL = -1;
int T[MAX_NODES + 1][2];
int main() {
assert(freopen("hashuri.in", "r", stdin));
assert(freopen("hashuri.out", "w", stdout));
int N; scanf("%d", &N);
int allocPtr = 1;
T[0][0] = T[0][1] = NIL;
while (N--) {
int opType, x; scanf("%d%d", &opType, &x);
if (opType == 1) {
int node = 0;
for (int i = MAX_LOG - 1; i >= 0; -- i) {
const bool bit = ((x >> i) & 1);
if (T[node][bit] == NIL) {
T[allocPtr][0] = T[allocPtr][1] = NIL;
T[node][bit] = allocPtr++;
}
node = T[node][bit];
}
} else if (opType == 2) {
int node = 0;
int i = MAX_LOG - 1;
while (i > 0 && node != NIL) {
node = T[node][((x >> i) & 1)];
-- i;
}
if (i == 0) {
T[node][x & 1] = NIL;
}
} else {
int node = 0;
int i = MAX_LOG - 1;
while (i >= 0 && node != NIL) {
node = T[node][((x >> i) & 1)];
-- i;
}
putchar('0' + (node != NIL));
putchar('\n');
}
}
fclose(stdin);
fclose(stdout);
return 0;
}