Pagini recente » Cod sursa (job #44937) | Cod sursa (job #2443388) | Cod sursa (job #3211491) | Cod sursa (job #1880834) | Cod sursa (job #611742)
Cod sursa(job #611742)
#include<cstdio>
#define infile "hashuri.in"
#define outfile "hashuri.out"
#define mod 666013
using namespace std;
typedef struct nod {
int inf;
nod *urm;
} *pnod;
pnod L[mod];
pnod find(int);
void add(int x)
{
if(find(x))
return;
int list = x % mod;
pnod p = new nod;
p->inf = x;
p->urm = L[list];
L[list] = p;
}
void erase(int x)
{
int list = x % mod;
pnod p = find(x);
if(!p)
return;
if(p == L[list])
{
L[list] = L[list]->urm;
delete p;
return;
}
pnod q = p->urm;
p->urm = p->urm->urm;
delete q;
}
pnod find(int x)
{
int list = x % mod;
pnod p = L[list];
if(!p)
return NULL;
if(p->inf == x)
return p;
while(p->urm)
{
if(p->urm->inf == x)
return p;
p = p->urm;
}
return NULL;
}
int main()
{
freopen(infile,"r",stdin);
freopen(outfile,"w",stdout);
int op, x, n;
scanf("%d",&n);
while(n--)
{
scanf("%d %d",&op,&x);
switch (op)
{
case 1: add(x); break;
case 2: erase(x); break;
case 3: printf("%d\n", (find(x)) ? 1 : 0 ); break;
}
}
fclose(stdin);
fclose(stdout);
return 0;
}