Pagini recente » Cod sursa (job #913409) | Cod sursa (job #54197) | Cod sursa (job #1480081) | Cod sursa (job #1375594) | Cod sursa (job #2288225)
#include <iostream>
#include <fstream>
#include <vector>
std::ifstream f("hashuri.in");
std::ofstream g("hashuri.out");
const int capacity = 499999;
class HashMap {
private:
std::vector<int> table[capacity];
int getHashKey(int value) {
return value % capacity;
}
std::vector<int>::iterator findValue(int key, int value) {
std::vector<int>::iterator sf = table[key].end();
std::vector<int>::iterator it;
for (it = table[key].begin(); it != sf; ++it)
if (*it == value)return it;
return sf;
}
public:
HashMap() {
}
void insert(int value) {
int key = this->getHashKey(value);
std::vector<int>::iterator it = findValue(key, value);
if (it == table[key].end())
table[key].push_back(value);
}
bool search(int value) {
int key = this->getHashKey(value);
std::vector<int>::iterator it = findValue(key, value);
return !(it == table[key].end());
}
void remove(int value) {
int key = this->getHashKey(value);
std::vector<int>::iterator it = findValue(key, value);
if (it != table[key].end())
table[key].erase(it);
}
};
int main() {
int n;
f >> n;
HashMap* h = new HashMap();
int op, x;
for (int i = 1; i <= n; ++i) {
f >> op >> x;
if (op == 1) {
h->insert(x);
continue;
}
if (op == 2) {
h->remove(x);
continue;
}
g << h->search(x) << '\n';
}
return 0;
}