Pagini recente » Cod sursa (job #2026979) | Cod sursa (job #1999861) | Cod sursa (job #2292541) | Cod sursa (job #1474493) | Cod sursa (job #1760775)
#include <stdio.h>
using namespace std;
#define MOD 673152
int liste[MOD], next[1000000], h[1000000];
int main()
{
int n, i, l, u, op, x, j;
FILE *fi=fopen("hashuri.in", "r"), *fo=fopen("hashuri.out", "w");
fscanf(fi, "%d", &n);
l=1;
for(i=0;i<n;i++){
fscanf(fi, "%d%d", &op, &x);
switch(op){
case 1:
for(j=liste[x%MOD];j!=0 && h[j]!=x;j=next[j]);
if(h[j]!=x){
h[l]=x;
next[l]=liste[x%MOD];
liste[x%MOD]=l;
}
l++;break;
case 2:
if(h[liste[x%MOD]]==x)
liste[x%MOD]=next[liste[x%MOD]];
else{
for(j=liste[x%MOD];j!=0 && h[j]!=x;j=next[j])
u=j;
if(h[j]==x)
next[u]=next[j];
}
break;
case 3:
for(j=liste[x%MOD];j!=0 && h[j]!=x;j=next[j]);
if(h[j]==x)
fprintf(fo, "1\n");
else
fprintf(fo, "0\n");
break;
}
}
fclose(fi);
fclose(fo);
return 0;
}