Pagini recente » Cod sursa (job #170300) | Cod sursa (job #2496006) | Cod sursa (job #2971874) | Cod sursa (job #135073) | Cod sursa (job #2160244)
#include<iostream>
#include<algorithm>
#include<vector>
#define MOD 666013
using namespace std;
vector<int> H[MOD];
vector<int>::iterator search(int x) {
int hash = x % MOD;
for (vector<int>::iterator it = H[hash].begin(); it != H[hash].end(); it++) {
if (*it == x) return it;
}
return H[hash].end();
}
void insert(int x) {
int hash = x % MOD;
if (search(x) == H[hash].end()) {
H[hash].push_back(x);
}
}
void erase(int x) {
int hash = x % MOD;
vector<int>::iterator it = search(x);
if (it != H[hash].end()) {
H[hash].erase(it);
}
}
bool exists(int x) {
int hash = x % MOD;
return search(x) != H[hash].end();
}
int main() {
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int N, op, x;
for (cin >> N; N; N--) {
cin >> op >> x;
if (op == 1) insert(x);
else if (op == 2) erase(x);
else cout << exists(x) << endl;
}
return 0;
}