Pagini recente » Cod sursa (job #3322311) | Cod sursa (job #1071571) | Cod sursa (job #3305600) | Cod sursa (job #3355391) | Cod sursa (job #3358021)
#include <fstream>
#include <vector>
#include <list>
#include <algorithm>
const int P = 1000003;
int hash(int x) {
return x % P;
}
int main() {
std::ifstream fin("hashuri.in");
std::ofstream fout("hashuri.out");
int N;
fin >> N;
std::vector<std::list<int>> table(P);
for (int i = 0; i < N; ++i) {
int op, x;
fin >> op >> x;
int h = hash(x);
auto& lst = table[h];
if (op == 1) {
if (std::find(lst.begin(), lst.end(), x) == lst.end()) {
lst.push_back(x);
}
} else if (op == 2) {
auto it = std::find(lst.begin(), lst.end(), x);
if (it != lst.end()) {
lst.erase(it);
}
} else if (op == 3) {
if (std::find(lst.begin(), lst.end(), x) != lst.end()) {
fout << "1\n";
} else {
fout << "0\n";
}
}
}
return 0;
}