Pagini recente » Cod sursa (job #470873) | Cod sursa (job #3233874) | Cod sursa (job #1735297) | Cod sursa (job #1035722) | Cod sursa (job #1128017)
#include <stdio.h>
#include <vector>
using namespace std;
#define MOD 666013
vector <int> hash_t[MOD];
inline int getHash(int x){
return x % MOD;
}
inline vector <int>::iterator searchHash(int x){
int ind = getHash(x);
vector <int>::iterator it;
for (it = hash_t[ind].begin(); it != hash_t[ind].end(); ++it)
if (*it == x)
return it;
return hash_t[ind].end();
}
inline void addHash(int x){
int ind = getHash(x);
if ( searchHash(x) == hash_t[ind].end() )
hash_t[ind].push_back(x);
}
inline void deleteHash(int x){
int ind = getHash(x);
vector <int>::iterator it = searchHash(x);
if (it != hash_t[ind].end())
hash_t[ind].erase(it);
}
int main(){
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int n, op, x;
scanf("%d", &n);
for (int i = 1; i <= n; ++i){
scanf("%d %d", &op, &x);
if (op == 1)
addHash(x);
else if (op == 2)
deleteHash(x);
else
printf("%d\n", searchHash(x) != hash_t[ getHash(x) ].end());
}
fclose(stdin);
fclose(stdout);
return 0;
}