Pagini recente » Cod sursa (job #768549) | Cod sursa (job #2853456) | Cod sursa (job #2124812) | Cod sursa (job #2672523) | Cod sursa (job #759481)
Cod sursa(job #759481)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define LIM 666013
vector<int>h[LIM];
vector<int>::iterator it;
int hash(int x){
return x%LIM;
}
bool find(int x){
int p=hash(x);
for(int i=0;i<h[p].size();i++)
if(h[p][i]==x)return 1;
return 0;
}
void insert(int x){
int p=hash(x);
if(!find(x))h[p].push_back(x);
}
void erase(int x){
int p=hash(x);
it=h[p].begin();
for(;it!=h[p].end();it++)
if(*it==x)
{
h[p].erase(it);
return;
}
}
int main(){
int m,c,x;
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&m);
while(m--)
{
scanf("%d %d",&c,&x);
switch(c)
{
case 1: insert(x); break;
case 2: erase(x); break;
case 3: printf("%d\n",find(x)); break;
}
}
return 0;
}