Pagini recente » Cod sursa (job #167582) | Cod sursa (job #296263) | Cod sursa (job #2702831) | Cod sursa (job #1629045) | Cod sursa (job #1790318)
#include<iostream>
#include<fstream>
#define NN 2500000
using namespace std;
void adauga(int x);
bool gaseste(int x);
void sterge(int x);
struct nod {
int val;
nod *next;
};
nod *h[NN];
int main(){
freopen ("hashuri.in", "r", stdin);
freopen ("hashuri.out", "w", stdout);
int n, x, a;
cin >> n;
while (n--){
cin >> a >> x;
switch (a) {
case 1: adauga(x); break;
case 2: sterge(x); break;
case 3: cout << gaseste(x) << '\n'; break;
}
}
}
void sterge(int x) {
nod *q = h[x % NN];
if (q == NULL) return;
if (q -> val == x) {
h[x % NN] = q -> next, delete(q);
} else {
nod *qq = q -> next;
while(qq != NULL && qq -> val != x) {
q = qq;
qq = qq -> next;
}
if (qq != NULL) {
q -> next = qq -> next;
delete(qq);
}
}
}
bool gaseste(int x) {
nod *q = h[x % NN];
while (q != NULL && q -> val != x) {
q = q -> next;
}
if (q != NULL) return 1;
return 0;
}
void adauga(int x) {
if (h[x % NN] == NULL) {
h[x % NN] = new nod;
h[x % NN] -> next = NULL;
h[x % NN] -> val = x;
} else {
nod *q = new nod;
q -> val = x;
q -> next = h[x % NN];
h[x % NN] = q;
}
}