Pagini recente » Cod sursa (job #751934) | Cod sursa (job #1646346) | Cod sursa (job #3186133) | Cod sursa (job #2941784) | Cod sursa (job #1968648)
#include <bits/stdc++.h>
using namespace std;
const int mod = (1 << 22) - 1;
int n;
vector < int > h[mod+1];
int nxt(int x) {
return (x * 17 + 1) & mod;
}
int _find(int x) {
int whr = ((x & mod) * 17) & mod;
for (int pos = 0; pos < h[whr].size(); ++pos)
if (h[whr][pos] == x) return pos;
return -1;
}
void _add(int x) {
int whr = ((x & mod) * 17) & mod;
int pos = _find(x);
if (pos != -1) return;
h[whr].push_back(x);
}
void _delete(int x) {
int whr = ((x & mod) * 17) & mod;
int pos = _find(x);
if (pos == -1) return;
h[whr][pos] = h[whr].back(); h[whr].pop_back();
}
int main() {
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int type, x;
scanf("%d %d", &type, &x);
if (type == 1)
_add(x);
if (type == 2)
_delete(x);
if (type == 3)
printf("%d\n", (_find(x) != -1));
}
return 0;
}