Pagini recente » Cod sursa (job #2866155) | Cod sursa (job #2906033) | Cod sursa (job #824632) | Cod sursa (job #2069477) | Cod sursa (job #2147702)
#include <iostream>
#include <fstream>
#include <vector>
#define modP 66013
using namespace std;
vector <int> H[modP];
inline vector<int>::iterator hashFindValue(int x) {
int list = x % modP;
for (vector<int>::iterator it = H[list].begin() ; it != H[list].end() ; ++it)
if (*it == x)
return it;
return H[list].end();
}
void hashInsertValue(int x) {
int list = x % modP;
if (hashFindValue(x) == H[list].end())
H[list].push_back(x);
}
void hashDeleteValue(int x) {
vector<int>::iterator it;
int list = x % modP;
it = hashFindValue(x);
if (it != H[list].end())
H[list].erase(it);
}
int main() {
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int N, op, x;
fin>>N;
while (N--) {
fin >> op >> x;
if (op == 1)
hashInsertValue(x);
else if (op == 2)
hashDeleteValue(x);
else if (op == 3) {
vector<int>::iterator it = hashFindValue(x);
it != H[x % modP].end() ? fout << "1\n" : fout << "0\n";
}
}
return 0;
}