Pagini recente » Cod sursa (job #243796) | Cod sursa (job #2615796) | Cod sursa (job #1828907) | Cod sursa (job #2673433) | Cod sursa (job #659419)
Cod sursa(job #659419)
#include <cstdio>
#include <list>
#define MOD 666013
using namespace std;
list<int> hash[MOD];
int n;
list<int>::iterator findValue(int x)
{
int xx = x%MOD;
list<int>::iterator it;
for(it=hash[xx].begin();it!=hash[xx].end();++it)
if(*it == x)
return it;
return hash[xx].end();
}
void insert(int x)
{
if(findValue(x) == hash[x%MOD].end())
hash[x%MOD].push_back(x);
}
void erase(int x)
{
list<int>::iterator it;
it=findValue(x);
if(it!=hash[x%MOD].end())
hash[x%MOD].erase(it);
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
int op,x;
for(int i=1;i<=n;i++)
{
scanf("%d",&op);
scanf("%d",&x);
if(op==1)
insert(x);
else if(op==2)
erase(x);
else
printf("%d\n", findValue(x)!=hash[x%MOD].end());
}
return 0;
}