Pagini recente » Cod sursa (job #915042) | Cod sursa (job #2930334) | Cod sursa (job #1445035) | Cod sursa (job #2522582) | Cod sursa (job #1564252)
//#include <iostream>
#include <fstream>
#include <cstdlib>
#define dim 99971
#define dim1 97073
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
int n,i,j;
int *Hv[99972];
int HHash(int x)
{
return (x%dim + (1 + x%dim1))%dim;
}
void Insert_H(int x)
{
int y=HHash(x);
if(Hv[y][0]==0)
{
Hv[y]=(int *)realloc(Hv[y],sizeof(int)*3);
Hv[y][0]=1;
Hv[y][1]=x;
}
else
{
for(int k=1;k<=Hv[y][0];++k)
if(x==Hv[y][k])
return;
Hv[y]=(int *)realloc(Hv[y],sizeof(int)*(Hv[y][0]+1));
++Hv[y][0];
Hv[y][Hv[y][0]]=x;
}
}
void Erase_H(int x)
{
int y=HHash(x);
for(int k=1;k<=Hv[y][0];++k)
if(x==Hv[y][k])
{
Hv[y][k]=0;
return;
}
}
bool Search_H(int x)
{
int y=HHash(x);
for(int k=1;k<=Hv[y][0];++k)
if(x==Hv[y][k])
return 1;
return 0;
}
int main()
{
cin>>n;
for(i=0;i<=dim;++i)
{
Hv[i]=(int *)realloc(Hv[i],sizeof(int)*2);
Hv[i][0]=0;
}
//cout<<"READY!\n";
while(cin>>i>>j)
{
//cout<<HHash(j)<<'\n';
if(i==1)
Insert_H(j);
if(i==2)
Erase_H(j);
if(i==3)
cout<<Search_H(j)<<'\n';
}
return 0;
}