Pagini recente » Cod sursa (job #3188751) | Cod sursa (job #1052277) | Cod sursa (job #543546) | Cod sursa (job #1220946) | Cod sursa (job #907158)
Cod sursa(job #907158)
#include <cstdio>
#include <cstring>
#define MOD 2097151
#define Prime 41
#define LUNG 32768
int Ap[MOD + 5];
char Buff[LUNG];
int Tip, X, N;
int i;
int p = LUNG - 1;
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);
}
inline void read(int &X)
{
X = 0;
while (Buff[p] < '0')
if (++p == LUNG) {
fread(Buff, 1, LUNG, stdin);
p = 0;
}
while (Buff[p] >= '0'){
X = X * 10 + Buff[p] - '0';
if (++p == LUNG){
fread(Buff, 1, LUNG, stdin);
p = 0;
}
}
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
read(N);
for (i = 1; i <= N; ++i){
read(Tip); read(X);
if (Tip == 1) insert(X);
if (Tip == 2) erase(X);
if (Tip == 3) printf("%d\n", find(X));
}
return 0;
}