Pagini recente » Cod sursa (job #1985862) | Cod sursa (job #1484375) | Cod sursa (job #1986333) | Cod sursa (job #1084752) | Cod sursa (job #2924812)
#include <fstream>
#include <map>
#include <vector>
#define MODULO 250000
using namespace std;
int main() {
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
map<int, vector<int>> hash_map;
int nr_operations, operation_type, number;
fin >> nr_operations;
for (int i = 0; i < nr_operations; ++i) {
fin >> operation_type >> number;
int key = number % MODULO;
if (operation_type == 1) {
if (hash_map.find(key) == hash_map.end()) {
vector<int> mapped_values;
mapped_values.push_back(number);
hash_map.insert({key, mapped_values});
} else {
vector<int>& mapped_values = hash_map.at(key);
int length = mapped_values.size();
bool is_found = false;
for (int i = 0; i < length; ++i) {
if (mapped_values[i] == number) {
is_found = true;
break;
}
}
if (!is_found) {
mapped_values.push_back(number);
}
}
} else if (operation_type == 2) {
if (hash_map.find(key) != hash_map.end()) {
vector<int>& mapped_values = hash_map.at(key);
int length = mapped_values.size();
for (int i = 0; i < length; ++i) {
if (mapped_values[i] == number) {
mapped_values.erase(mapped_values.begin() + i);
break;
}
}
}
} else {
if (hash_map.find(key) != hash_map.end()) {
vector<int> mapped_values = hash_map.at(key);
int length = mapped_values.size();
bool is_found = false;
for (int i = 0; i < length; ++i) {
if (mapped_values[i] == number) {
fout << 1 << '\n';
is_found = true;
break;
}
}
if (!is_found) {
fout << 0 << '\n';
}
} else {
fout << 0 << '\n';
}
}
}
return 0;
}