Pagini recente » Cod sursa (job #985842) | Cod sursa (job #1769387) | Cod sursa (job #1433431) | Cod sursa (job #785482) | Cod sursa (job #767434)
Cod sursa(job #767434)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 666013
vector<int>v[MOD];
inline int hash(int x){ return x%MOD; }
vector<int>::iterator find(int p,int x){
vector<int>::iterator it = v[p].begin();
while( it != v[p].end() )
{
if( *it == x ) return it;
it++;
}
return it;
}
void add(int x){
int p = hash(x);
if( find(p,x) == v[p].end() )v[p].push_back(x);
}
void remove(int x){
int p = hash(x);
vector<int>::iterator it = find(p,x);
if( it != v[p].end() )v[p].erase(it);
}
bool este(int x){
int p = hash(x);
if( find(p,x) != v[p].end() ) return 1;
return 0;
}
int main(){
int n,c,x;
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
while(n--)
{
scanf("%d %d",&c,&x);
switch(c){
case 1: add(x); break;
case 2: remove(x); break;
case 3: printf("%d\n",este(x)); break;
}
}
return 0;
}