Pagini recente » Cod sursa (job #2663582) | Cod sursa (job #1376277) | Cod sursa (job #3274410) | Cod sursa (job #3254651) | Cod sursa (job #803994)
Cod sursa(job #803994)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define MOD 100000
vector<int> ht[MOD];
inline vector<int>::iterator find_ht(int x) {
int h = x % MOD;
vector<int>::iterator iter;
for (iter = ht[h].begin(); iter != ht[h].end(); ++iter)
if (*iter == x) return iter;
return ht[h].end();
}
inline void insert_ht(int x) {
int h = x % MOD;
if (find_ht(x) == ht[h].end())
ht[h].push_back(x);
}
inline void delete_ht(int x) {
int h = x % MOD;
vector<int>::iterator iter = find_ht(x);
if (iter != ht[h].end()) {
*iter = ht[h].back(); // move the last element in the place of this one
ht[h].pop_back(); // pop the last element
}
}
int main() {
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int n, op, val;
scanf("%d", &n);
for (int i=0; i<n; ++i) {
scanf("%d %d", &op, &val);
if (op == 1) {
insert_ht(val);
} else if (op == 2) {
delete_ht(val);
} else {
printf("%d\n", find_ht(val) != ht[val%MOD].end());
}
}
return 0;
}