Pagini recente » Cod sursa (job #1649694) | Cod sursa (job #1226560) | Cod sursa (job #2200315) | Cod sursa (job #3319324) | Cod sursa (job #3318000)
#include <algorithm>
#include<cstdio>
#include<vector>
using namespace std;
const int MOD = 666013;
vector<int> v[MOD]; // hash cu adresa
bool inHash(int x) {
int position = x % MOD;
for (auto element : v[position]) {
if (element == x) {
return true;
}
}
return false;
}
void addElement(int x) {
if (inHash(x))
return;
int position = x % MOD;
v[position].push_back(x);
}
void deleteElement(int x) {
if (!inHash(x))
return;
int position = x % MOD;
auto it = find(v[position].begin(), v[position].end(), x);
if (it != v[position].end()) {
v[position].erase(it);
}
}
int main(){
int n;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d",&n);
for (int i = 0; i < n; i++) {
int op, x;
scanf("%d %d", &op, &x);
if (op == 1) {
addElement(x);
}
else if (op == 2) {
deleteElement(x);
}
else {
printf("%d\n",inHash(x));
}
}
return 0;
}