Pagini recente » Cod sursa (job #2525300) | Cod sursa (job #2426995) | Cod sursa (job #1706007) | Cod sursa (job #2941236) | Cod sursa (job #2642857)
#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 NMAX = 99991;
vector<int> HashTable[NMAX];
int HASH(int x)
{
double k = (double)x * 0.13;
double p = (double)(1LL << 13LL) * 0.37;
return(int)(k * p) % NMAX;
}
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);
}
}