Pagini recente » Cod sursa (job #2461037) | Cod sursa (job #1158142) | Cod sursa (job #56139) | Cod sursa (job #1747691) | Cod sursa (job #2154957)
#include <bits/stdc++.h>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int mod = 666013, MaxN = 1000005;
int n, urm[MaxN], val[MaxN], start[mod], ind, fr[MaxN];
void Del(int x) {
int poz = start[x % mod];
if (val[poz] == x) {
//--fr[poz];
start[x % mod] = urm[poz];
return;
}
while (urm[poz] && val[urm[poz]] != x) poz = urm[poz];
//if (val[urm[poz]] == x) --fr[urm[poz]];
urm[poz] = urm[urm[poz]];
}
int Check(int x) {
int poz = start[x % mod];
while (poz && val[poz] != x) poz = urm[poz];
return poz;
}
void Add(int x) {
if (Check(x)) {
//++fr[Check(x)];
return;
}
val[++ind] = x;
urm[ind] = urm[start[x % mod]];
start[x % mod] = ind;
}
int main()
{
f >> n;
for (int i = 1; i <= n; ++i) {
int op, x;
f >> op >> x;
if (op == 1) {
Add(x);
}
else if (op == 2) Del(x);
else g << (bool)Check(x) << '\n';
}
return 0;
}