Pagini recente » Cod sursa (job #115767) | Cod sursa (job #1943344) | Cod sursa (job #1489004) | Cod sursa (job #309077) | Cod sursa (job #1306969)
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <vector>
using namespace std;
const int M = 666013;
vector<int> H[M];
int hash_func(int value)
{
return value % M;
}
void Add(int value)
{
int where = hash_func(value);
H[where].push_back(value);
}
void Delete(int value)
{
int where=hash_func(value);
vector<int>::iterator it;
for(it=H[where].begin(); it != H[where].end(); ++it)
{
if(*it == value)
{
H[where].erase(it);
return;
}
}
}
int Query(int value)
{
int where=hash_func(value);
vector<int>::iterator it;
for(it=H[where].begin(); it!= H[where].end();++it)
{
if(*it == value)
return 1;
}
return 0;
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int i,j,n,x,y;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %d",&x,&y);
if(x==1)
{
Add(y);
}
else if(x==2)
{
Delete(y);
}
else
{
printf("%d\n",Query(y));
}
}
}