Pagini recente » Cod sursa (job #3247404) | Cod sursa (job #481894) | Cod sursa (job #890229) | Cod sursa (job #1596306) | Cod sursa (job #2892143)
#include <bits/stdc++.h>
using namespace std;
const int MOD = 665993;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n, tip, x, stackSize;
vector<int> st, h;
struct hash2 {
int v{}, n{};
};
vector<hash2> l;
inline bool find(const int &y) {
int i = h[y - (y / MOD) * MOD];
while (i != -1 && l[i].v != y) {
i = l[i].n;
}
return i != -1;
}
inline void insert(const int &y) {
/*
if (find(y)) {
return;
}
*/
int hash = y - (y / MOD) * MOD;
int p;
if (!st.empty()) {
p = st.back();
st.pop_back();
} else {
p = stackSize++;
}
if (p == l.size()) {
hash2 temp;
l.emplace_back(temp);
}
l[p].v = y;
l[p].n = h[hash];
h[hash] = p;
}
inline void erase(const int &y) {
int hash = y - (y / MOD) * MOD;
int i = h[hash];
if (i == -1) {
return;
}
if (l[i].v == y) {
st.emplace_back(i);
h[hash] = l[i].n;
} else {
while (l[i].n != -1 && l[l[i].n].v != y) {
i = l[i].n;
}
if (l[i].n != -1) {
st.emplace_back(l[i].n);
l[i].n = l[l[i].n].n;
}
}
}
signed main() {
ios::sync_with_stdio(false);
in.tie();
out.tie();
h.resize(MOD, -1);
in >> n;
for (; n; --n) {
in >> tip >> x;
if (tip == 1) {
insert(x);
}
if (tip == 2) {
erase(x);
}
if (tip == 3) {
out << find(x) << '\n';
}
}
return 0;
}