Pagini recente » Cod sursa (job #2098043) | Cod sursa (job #3282382) | Cod sursa (job #2919785) | Cod sursa (job #306799) | Cod sursa (job #1171229)
#include <vector>
#include <fstream>
static const int BUCKET_COUNT = 666013;
typedef std::vector<std::vector<int>> hash_t;
int hash_f(int n) {
return n % BUCKET_COUNT;
}
void add(hash_t& hash, int n) {
hash[hash_f(n)].push_back(n);
}
void remove(hash_t& hash, int n) {
int bucket = hash_f(n);
for (auto i : hash) {
if (i == n) {
i = -1;
}
}
}
bool search(hash_t& hash, int n) {
int bucket = hash_f(n);
for (auto const& i : hash[bucket]) {
if (i == n) {
return true;
}
}
return false;
}
int main() {
hash_t h(BUCKET_COUNT);
std::ifstream fin("hashuri.in");
std::ofstream fout("hashuri.out");
int n;
fin >> n;
while (n) {
int op, arg;
fin >> op >> arg;
switch(op) {
case 1:
add(h, arg);
break;
case 2:
remove(h, arg);
break;
case 3:
fout << search(h, arg) << std::endl;
break;
}
n--;
}
fin.close();
fout.close();
return 0;
}