Pagini recente » Cod sursa (job #336919) | Cod sursa (job #1470159) | Cod sursa (job #1059686) | Cod sursa (job #3135067) | Cod sursa (job #1400917)
#include<fstream>
#define MOD 666013
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
typedef struct lnod{
int nr;
lnod *next;
}*nod;
int n,t,x;
nod HASH[1000005];
bool u;
void add(int x, nod &y){
nod p=new lnod;
p->nr=x;
p->next=y;
y=p;
}
bool find(int x){
nod p;
for(p=HASH[x%MOD];p;p=p->next) if(p->nr==x)return 1;
return 0;
}
void del(int x) {
nod p=HASH[x%MOD],r;
while(p)
if(p->nr==x) if(p==HASH[x%MOD]) if(p->next==NULL) { HASH[x%MOD]=NULL;delete p; return; }
else { HASH[x%MOD]=p->next;delete p; return; }
else {
r->next=p->next;
delete p;
return;
}
else r=p,p=p->next;
}
main(void)
{
cin>>n;
for(int i=1;i<=n;++i){
cin>>t>>x;
u=find(x);
if(t==1)add(x,HASH[x%MOD]);
if(t==2)del(x);
if(t==3)cout<<u<<'\n';
}
}