Pagini recente » Cod sursa (job #2319292) | Cod sursa (job #2715211) | Cod sursa (job #1490519) | Borderou de evaluare (job #1698049) | Cod sursa (job #799677)
Cod sursa(job #799677)
#include <fstream>
#include <vector>
using namespace std;
ifstream in ("hashuri.in");
ofstream out ("hashuri.out");
const int modulo = 666317;
struct hash {
vector <int> v[modulo+1];
/*hash () {
}*/
void insert (int x) {
v[x % modulo].push_back(x);
}
void erase (int x) {
int xmod = x % modulo;
for (vector<int>::iterator it = v[xmod].begin(); it != v[xmod].end(); ++it) {
if (*it == x) {
//int aux = *it;
*it = v[xmod].back();
//v[xmod].back() = aux;
v[xmod].pop_back();
return;
}
}
}
bool exist (int x) {
int xmod = x % modulo;
for (vector<int>::iterator it = v[xmod].begin(); it != v[xmod].end(); ++it) {
if (*it == x) {
return true;
}
}
return false;
}
};
int n;
hash h;
void citire () {
in >> n;
int op,x;
while (n--) {
in >> op >> x;
if (op == 1) {
h.insert (x);
}
if (op == 2) {
h.erase (x);
}
if (op == 3) {
out << h.exist (x) << '\n';
}
}
}
int main () {
citire ();
return 0;
}