Pagini recente » Borderou de evaluare (job #751010) | Cod sursa (job #3211661) | Cod sursa (job #470453) | Cod sursa (job #1541861) | Cod sursa (job #586697)
Cod sursa(job #586697)
#include <cstdio>
#include <vector>
using namespace std;
const int MOD = 711713;
vector <int> hash[MOD + 3];
vector <int> :: iterator find_hash(int x) {
int r = x % MOD;
for (vector <int> :: iterator it = hash[r].begin(); it != hash[r].end(); ++ it)
if (*it == x)
return it;
return hash[r].end();
}
void insert_hash(int x) {
vector <int> :: iterator it = find_hash(x);
int r = x % MOD;
if (it == hash[r].end())
hash[r].push_back(x);
}
void erase_hash(int x) {
vector <int> :: iterator it = find_hash(x);
int r = x % MOD;
if (it != hash[r].end())
hash[r].erase(it);
}
void query_hash(int x) {
vector <int> :: iterator it = find_hash(x);
int r = x % MOD;
if (it == hash[r].end())
printf("0\n");
else
printf("1\n");
}
int main() {
int n, tip, nb;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n; ++ i) {
scanf("%d%d", &tip, &nb);
if (tip == 1)
insert_hash(nb);
else if (tip == 2)
erase_hash(nb);
else
query_hash(nb);
}
return 0;
}