Pagini recente » Cod sursa (job #194211) | Cod sursa (job #1805610) | Cod sursa (job #215499) | Cod sursa (job #2325401) | Cod sursa (job #2083034)
#include <bits/stdc++.h>
#define MOD 666013
#define MAXN 1000000
#define BUF_SIZE 1 << 14
char buf[BUF_SIZE];
int pbuf=BUF_SIZE;
FILE*fi,*fo;
inline char nextch(){
if(pbuf==BUF_SIZE){
fread(buf, BUF_SIZE, 1, fi);
pbuf=0;
}
return buf[pbuf++];
}
inline int nextnum(){
int a = 0;
char c = nextch();
while(!isdigit(c))
c = nextch();
while(isdigit(c)){
a = a * 10 + c - '0';
c = nextch();
}
return a;
}
class Hash{
public:
int k=0, next[MAXN+1], *lista;
int val[MAXN+1];
int d[MAXN+1];
Hash() {
lista = new int[MOD];
memset(lista, 0x00, MOD*sizeof(int));
}
inline void insert(int element, int frecventa){
k++;
val[k]=element;
d[k]=frecventa;
next[k]=lista[element%MOD];
lista[element%MOD]=k;
}
inline void erase(int element){
int p=lista[element%MOD];
if(p==0)
return ;
if(val[p]==element){
lista[element%MOD]=next[lista[element%MOD]];
return ;
}
while(next[p]!=0 && val[next[p]]!=element)
p=next[p];
if(next[p]!=0){
next[p]=next[next[p]];
}
}
inline int find(int element){
int p=lista[element%MOD];
while(p!=0 && val[p]!=element)
p=next[p];
if(p!=0)
return p;
return 0;
}
} H;
int main(){
fi=fopen("hashuri.in","r");
fo=fopen("hashuri.out","w");
int n=nextnum();
for(int i=0;i<n;i++){
int c=nextnum();
int val=nextnum();
if(c==1){
if(!H.find(val))
H.insert(val, 1);
}
else if(c==2)
H.erase(val);
else{
if(H.find(val))
fprintf(fo,"1\n");
else
fprintf(fo,"0\n");
}
}
fclose(fi);
fclose(fo);
return 0;
}