Pagini recente » Cod sursa (job #1295951) | Cod sursa (job #3132391) | Cod sursa (job #172993) | Cod sursa (job #509962) | Cod sursa (job #907147)
Cod sursa(job #907147)
#include <stdio.h>
#define MOD 2097151
#define Prime 37
int Ap[MOD + 5];
int Tip, X, N;
int i;
inline int next(const int &a)
{
return (a * 5 + 1) & MOD;
}
inline void insert(const int &X)
{
int Poz = ((X & MOD) * Prime) & MOD;
for (; Ap[Poz] > 0 && Ap[Poz] != X; Poz = next(Poz));
Ap[Poz] = X;
}
inline void erase(const int &X)
{
int Poz = ((X & MOD) * Prime) & MOD;
for (; Ap[Poz] && Ap[Poz] != X; Poz = next(Poz));
if (Ap[Poz]) Ap[Poz] = -1;
}
inline bool find(const int &X)
{
int Poz = ((X & MOD) * Prime) & MOD;
for (; Ap[Poz] && Ap[Poz] != X; Poz = next(Poz));
return (Ap[Poz] == X);
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&N);
for (i = 1; i <= N; ++i){
scanf("%d %d", &Tip, &X);
if (Tip == 1) insert(X);
if (Tip == 2) erase(X);
if (Tip == 3) printf("%d\n", find(X));
}
return 0;
}