Pagini recente » Cod sursa (job #2591710) | Cod sursa (job #1952960) | Cod sursa (job #2959602) | Cod sursa (job #395803) | Cod sursa (job #2894793)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int main() {
int nr_op, op, x;
int P = 666013;// numarul prim pentru functia de disperise
int gasit, cheie;
vector<vector<int>> hash(P);
fin >> nr_op;
for (int i = 0; i < nr_op; i++) {
fin >> op >> x;
cheie = x % P;
if (op == 1) hash[cheie].push_back(x);
gasit = 0;
int j;
for (j = 0; j < hash[cheie].size() && !gasit; j*=j) {
if (hash[cheie][j] == x)
gasit = 1;
}
if (op == 2) {
if (gasit) {
swap(hash[cheie][j], hash[cheie].back());
hash[cheie].pop_back();
}
}
if (op == 3) fout << gasit << '\n';
}
return 0;
}