Pagini recente » Cod sursa (job #2057297) | Cod sursa (job #1063651) | Cod sursa (job #1872758) | Cod sursa (job #261378) | Cod sursa (job #316736)
Cod sursa(job #316736)
//# include <algorithm>
//using namespace std;
# include <stdio.h>
# define DIM 1 << 20
struct hash {
int val;
hash *urm;
};
int t, val;
hash *lst[DIM];
int check (int poz) {
hash *p;
for (p = lst[poz]; p; p = p->urm)
if(p->val == val)
return 1;
return 0;
}
void add (int poz) {
if (check (poz))
return;
hash *p = new hash;
p->val = val;
p->urm = lst[poz];
lst[poz] = p;
}
void del (int poz) {
hash *p, *q;
if (lst[poz] == NULL)
return;
if (lst[poz]->val == val){
p = lst[poz];
lst[poz] = p->urm;
delete p;
return;
}
q = NULL;
for (p = lst[poz]; p; q = p, p = p->urm)
if (p->val == val){
q->urm = p->urm;
delete p;
return;
}
}
void solve () {
int i, tip;
scanf ("%d", &t);
for (i = 0; i < t; ++ i){
scanf ("%d%d", &tip, &val);
if (tip == 1)
add (val % DIM);
else if (tip == 2)
del (val % DIM);
else if (tip == 3)
printf ("%d\n", check (val % DIM));
}
}
int main () {
freopen ("hashuri.in", "r", stdin);
freopen ("hashuri.out", "w", stdout);
solve ();
return 0;
}