Pagini recente » Cod sursa (job #2606210) | Borderou de evaluare (job #838894) | Cod sursa (job #2452403) | Cod sursa (job #3142265) | Cod sursa (job #1256020)
#include <iostream>
#include <fstream>
#include <vector>
const int MOD = 666013;
class Hash {
private:
std::vector<int> a[MOD];
public:
Hash() {
}
void insert(int x) {
int id = x % MOD;
a[id].push_back(x);
}
void erase(int x) {
int i = x % MOD;
for (size_t j = 0; j < a[i].size(); j++) {
if (a[i][j] == x) {
a[i].erase(a[i].begin() + j);
j--;
}
}
}
bool has(int x) {
int i = x % MOD;
for (size_t j = 0; j < a[i].size(); j++) {
if (a[i][j] == x) {
return true;
}
}
return false;
}
};
std::ifstream f("hashuri.in");
std::ofstream g("hashuri.out");
Hash hash;
int main()
{
int n;
f >> n;
for (int i = 1; i <= n; i++) {
int op, x;
f >> op >> x;
if (op == 1) hash.insert(x);
if (op == 2) hash.erase(x);
if (op == 3) g << hash.has(x) << '\n';
}
f.close();
g.close();
return 0;
}