Cod sursa(job #1729962)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 15 iulie 2016 22:27:30
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f ("hashuri.in");
ofstream t ("hashuri.out");

int32_t v[10000010];
const int key=43;

inline int32_t hashcode(int32_t x){
return (x*key+x/key)%10000000;}

inline void increment(int &a){
if (++a==10000000) a=0;
}

inline void hash_add(int32_t x){int32_t a=hashcode(x),i;
for(i=a;v[i]!=0 and v[i]!=x;increment(i));
if(v[i]==x) return;
for(i=a;v[i]>0;increment(i));
v[i]=x;
}

inline void hash_erase(int32_t x){int32_t i=hashcode(x);
while(v[i]!=0){
if (v[i]==x)v[i]=-1;
increment(i);
}}

inline bool hash_verify(int32_t x){int32_t i=hashcode(x);
while(v[i]!=0){
if (v[i]==x) return 1;
increment(i);
}
return 0;
}

int main()
{int32_t n,q,x;
f>>n;
for (int i=0;i<n;++i){
f>>q>>x;
if (q==1)
hash_add(x);
else if(q==2)
hash_erase(x);
else if(q==3)
cout<<hash_verify(x)<<'\n';}
return 0;
}