Pagini recente » Cod sursa (job #604322) | Cod sursa (job #986093) | Cod sursa (job #1193878) | Cod sursa (job #528352) | Cod sursa (job #3131929)
#include <iostream>
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;
vector<int> hash_table[MOD];
inline vector<int>::iterator find_hash(int x)
{
int pos = x % MOD;
vector<int>::iterator it;
for (it = hash_table[pos].begin(); it != hash_table[pos].end(); it++)
{
if (*it == x)
return it;
}
return hash_table[pos].end();
}
inline void insert_hash(int x)
{
int pos = x % MOD;
if (find_hash(x) == hash_table[pos].end())
hash_table[pos].push_back(x);
}
inline void del_hash(int x)
{
int pos = x % MOD;
vector<int>::iterator it = find_hash(x);
if (it != hash_table[pos].end())
hash_table[pos].erase(it);
}
int main()
{
ifstream input("hashuri.in");
ofstream output("hashuri.out");
int n, op, x;
input >> n;
for (int i = 1; i <= n; i++)
{
input >> op >> x;
if (op == 1)
insert_hash(x);
else if (op == 2)
del_hash(x);
else if (op == 3)
{
if (find_hash(x) != hash_table[x % MOD].end())
output << 1 << '\n';
else
output << 0 << '\n';
}
}
output << '\n';
input.close();
output.close();
return 0;
}