Pagini recente » Cod sursa (job #680919) | Cod sursa (job #428564) | Cod sursa (job #2303868) | Cod sursa (job #2180745) | Cod sursa (job #605621)
Cod sursa(job #605621)
#include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;
int n;
vector<long> vec[99999];
inline int hash(int val)
{
//return val % 10000;
double A = 545.6463;
double s = val*A;
double sec;
double x = modf(s , &sec);
double m = 0.5*(sqrt(5) - 1);
return floor(m*x);
}
inline void add(int val)
{
int poz = hash(val);
vec[poz].push_back(val);
}
vector<long>::iterator find(int val)
{
int poz = hash(val);
vector<long>::iterator it;
for (it = vec[poz].begin(); it != vec[poz].end(); ++it)
{
if (*it == val)
{
return it;
}
}
return vec[poz].end();
}
inline void del(int val)
{
vector<long>::iterator it = find(val);
int poz = hash(val);
if (it != vec[poz].end())
vec[poz].erase(it);
}
void findd(int val)
{
int poz = hash(val);
vector<long>::iterator it = find(val);
if (it != vec[poz].end())
printf("%d\n", 1);
else
printf("%d\n", 0);
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d", &n);
int op, param;
for (int i = 0; i < n; ++i)
{
scanf("%d%d", &op, ¶m);
switch(op)
{
case(1): add(param); break;
case(2): del(param); break;
case(3): findd(param); break;
}
}
return 0;
}