Pagini recente » Cod sursa (job #150241) | Cod sursa (job #2550127) | Cod sursa (job #1266323) | Cod sursa (job #3166361) | Cod sursa (job #2642864)
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <set>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int MOD = 999983;//preferably a prime number
vector<int> HashTable[MOD+1];
int HASH(int x)
{
return x % MOD;
}
void insert(int x)
{
int pos = HASH(x);
for (auto const& it : HashTable[pos])
{
if (it == x)
return;
}
HashTable[pos].push_back(x);
}
void del(int x)
{
int pos = HASH(x);
for (int i = 0; i < HashTable[pos].size(); i++)
{
if (HashTable[pos][i] == x)
HashTable[pos].erase(HashTable[pos].begin() + i);
}
}
void inTable(int x)
{
int pos = HASH(x);
for (auto const& it : HashTable[pos])
{
if (it == x)
{
out << 1 << '\n'; return;
}
}
out << 0 << '\n';
}
int main()
{
int n;
for (in >> n; n--;)
{
int op, x;
in >> op >> x;
if (op == 1)
insert(x);
else
if (op == 2)
del(x);
else
inTable(x);
}
}