Pagini recente » Cod sursa (job #2331923) | Cod sursa (job #479265) | Cod sursa (job #768201) | Cod sursa (job #298711) | Cod sursa (job #763643)
Cod sursa(job #763643)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 666013
vector<int>g[MOD];
inline int hash(int x){ return x%MOD; }
bool find(int x){
int p = hash(x);
for(int i=0;i<g[p].size();i++)
if(g[p][i] == x)return 1;
return 0;
}
void add(int x){
int p = hash(x);
if(!find(x))g[p].push_back(x);
}
void remove(int x){
int p = hash(x);
vector<int>::iterator it = g[p].begin();
while(it != g[p].end())
{
if(*it == x)
{
g[p].erase(it);
return ;
}
it++;
}
}
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: add(x); break;
case 2: remove(x); break;
case 3: printf("%d\n",find(x)); break;
}
}
return 0;
}