Pagini recente » Cod sursa (job #14022) | Cod sursa (job #1058926) | Cod sursa (job #184143) | Cod sursa (job #2757419) | Cod sursa (job #1579219)
#include <stdio.h>
using namespace std;
FILE *in=fopen("hashuri.in","r");
FILE *out=fopen("hashuri.out","w");
const double R=666013;
const int N=1000001;
const double A=0.618034;
int lst[666013],val[N],urm[N];
int m;
inline int h(double x){
return (int)(R * (A * x - (int)(A * x)));
}
inline void adauga (int x)
{
int tip=h(x);
val[++m]=x;
urm[m]=lst[tip];
lst[tip]=m;
}
void sterge (int x)
{
int tip=h(x),p;
p=lst[tip];
if(x==val[p])
lst[tip]=urm[p];
while(urm[p]!=0)
{
if(x==val[urm[p]])
urm[p]=urm[urm[p]];
p=urm[p];
}
}
bool cauta (int x)
{
int p=lst[h(x)];
while(p!=0)
{
if(x==val[p])
return 1;
p=urm[p];
}
return 0;
}
int main()
{
int n,i,op,x;
fscanf(in,"%d",&n);
for(i=0;i<n;i++)
{
fscanf(in,"%d%d",&op,&x);
if(op==1)
adauga(x);
if(op==2)
sterge(x);
if(op==3)
fprintf(out,"%d\n",cauta(x));
}
return 0;
}