Pagini recente » Cod sursa (job #242113) | Cod sursa (job #64596) | Cod sursa (job #369663) | Cod sursa (job #25057) | Cod sursa (job #2154526)
#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];
void Add(int x) {
int poz = val[x] % mod;
if (!start[poz]) {
start[poz] = x;
return;
}
int y = start[poz];
while (y && val[y] != val[x]) y = urm[y];
if (!y) {
urm[x] = start[poz];
start[poz] = x;
}
}
void Del(int x) {
int poz = x % mod;
if (!start[poz]) return;
int y = start[poz];
if (val[y] == x) {
start[poz] = urm[y];
return;
}
while (urm[y] && val[urm[y]] != x) y = urm[y];
urm[y] = urm[urm[y]];
}
bool Check(int x) {
int poz = x % mod;
if (!start[poz]) return 0;
int y = start[poz];
while (y && val[y] != x) y = urm[y];
if (y) return 1;
return 0;
}
int main()
{
f >> n;
for (int i = 1; i <= n; ++i) {
int op, x;
f >> op >> x;
if (op == 1) {
val[i] = x;
Add(i);
}
else if (op == 2) Del(x);
else g << Check(x) << '\n';
}
return 0;
}