Pagini recente » Cod sursa (job #1961887) | Cod sursa (job #2390433) | Cod sursa (job #2552344) | Cod sursa (job #1017851) | Cod sursa (job #616718)
Cod sursa(job #616718)
#include <fstream>
#include <cstring>
#define HSize 999983
#define MOD 999983
using namespace std;
ifstream in;
ofstream out;
struct hash
{
int nod;
hash *link;
}*H[HSize];
inline int find(int val)
{
for(hash *h=H[val%MOD];h;h=h->link)
if(h->nod==val) return 1;
return 0;
}
inline void ins(int val)
{
hash *h=new hash;
h->nod=val;
val%=MOD;
h->link=H[val];
H[val]=h;
}
inline void del(int val)
{
for(hash *aux=NULL,*h=H[val%MOD];h;aux=h,h=h->link)
if(h->nod==val)
{
if(aux) aux->link=h->link;
else H[val%MOD]=h->link;
delete h;
return;
}
}
int main()
{
int N,x,y,ok;
in.open("hashuri.in");
out.open("hashuri.out");
in>>N;
for(;N--;)
{
in>>x>>y;
ok=find(y);
if(x==1&&!ok) ins(y);
else
if(x==2&&ok) del(y);
else
if(x==3) out<<ok<<'\n';
}
in.close();
out.close();
return 0;
}