Pagini recente » Cod sursa (job #57892) | Cod sursa (job #2721332) | Cod sursa (job #1360824) | Cod sursa (job #1059125) | Cod sursa (job #1495369)
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector<int> myhash[MOD];
vector<int>::iterator myfind(int key) {
int bucketIndex = key % MOD;
vector<int> & bucket = myhash[bucketIndex];
for (vector<int>::iterator it = bucket.begin();
it != bucket.end(); ++it) {
if (*it == key)
return it;
}
return bucket.end();
}
void myinsert(int x) {
if (myfind(x) == myhash[x % MOD].end()) {
myhash[x % MOD].push_back(x);
}
}
void myerase(int x) {
vector<int>::iterator it = myfind(x);
if (it != myhash[x % MOD].end()) {
myhash[x % MOD].erase(it);
}
}
int main()
{
int N, op, x;
fin >> N;
for (int i = 1; i <= N; ++i) {
fin >> op >> x;
if (op == 1) {
myinsert(x);
} else if (op == 2) {
myerase(x);
} else {
fout << (myfind(x) != myhash[x % MOD].end()) << '\n';
}
}
return 0;
}