Pagini recente » Cod sursa (job #1821897) | Cod sursa (job #783562) | Cod sursa (job #671159) | Cod sursa (job #71990) | Cod sursa (job #883594)
Cod sursa(job #883594)
#include <cstdio>
#include <cassert>
#include <vector>
using namespace std;
typedef vector<int>::iterator it;
const int U = 666013;
vector<int> H[U];
inline int Search(int X) {
int Key = X % U;
for (it V = H[Key].begin(); V != H[Key].end(); ++V)
if (*V == X)
return 1;
return 0;
}
inline void Insert(int X) {
int Key = X % U;
if (!Search(X))
H[Key].push_back(X);
}
inline void Erase(int X) {
int Key = X % U;
for (it V = H[Key].begin(); V != H[Key].end(); ++V) {
if (*V == X) {
H[Key].erase(V);
return;
}
}
}
int main() {
assert(freopen("hashuri.in", "r", stdin));
assert(freopen("hashuri.out", "w", stdout));
int Q; assert(scanf("%d", &Q) == 1);
for (; Q > 0; --Q) {
int Type, X; assert(scanf("%d %d", &Type, &X) == 2);
if (Type == 1)
Insert(X);
if (Type == 2)
Erase(X);
if (Type == 3)
printf("%d\n", Search(X));
}
return 0;
}