Pagini recente » Cod sursa (job #1779344) | Cod sursa (job #575378) | Cod sursa (job #2194236) | Borderou de evaluare (job #133609) | Cod sursa (job #3266298)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
#define MOD 666013
vector<int> H[MOD];
int hash_func(int x) {
return x % MOD;
}
bool caut(int x) {
int h = hash_func(x);
for (auto it : H[h]) {
if (it == x) {
return 1;
}
}
return 0;
}
void insert_x(int x) {
int h = hash_func(x);
if (caut(x) == 0) {
H[h].push_back(x);
}
}
void delete_x(int x) {
int h = hash_func(x);
for (int i = 0; i < H[h].size(); ++i) {
if (H[h][i] == x) {
H[h].erase(H[h].begin() + i);
return;
}
}
}
int main() {
int n;
fin >> n;
for (int i = 1; i <= n; ++i) {
int op, x;
fin >> op >> x;
if (op == 1) {
insert_x(x);
} else if (op == 2) {
delete_x(x);
} else {
fout << caut(x) << '\n';
}
}
return 0;
}