Pagini recente » Cod sursa (job #1487636) | Cod sursa (job #38704) | Cod sursa (job #1093585) | Cod sursa (job #517960) | Cod sursa (job #734835)
Cod sursa(job #734835)
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define SIZE 666013
typedef vector< vector<int> > Hash;
//Hash hash(SIZE, vector<int>());
vector<int> hash[SIZE];
inline bool in_hash(int what)
{
int hs = what % SIZE;
vector<int>::iterator it;
for(it = hash[hs].begin(); it != hash[hs].end(); it++)
{
if(*it == what)
{
return true;
}
}
return false;
}
inline void insert(int what)
{
int hs = what % SIZE;
if(!in_hash(what))
{
hash[hs].push_back(what);
}
}
inline void del(int what)
{
int hs = what % SIZE;
vector<int>::iterator it;
for(it = hash[hs].begin(); it != hash[hs].end(); it++)
{
if(*it == what)
{
hash[hs].erase(it);
return;
}
}
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int N, Type, X;
scanf("%d", &N);
for(int i=0; i<N; i++)
{
scanf("%d %d", &Type, &X);
switch(Type)
{
case 1:
insert(X);
break;
case 2:
del(X);
break;
case 3:
printf("%d\n", in_hash(X));
break;
}
}
return 0;
}