Pagini recente » Cod sursa (job #1213126) | Cod sursa (job #2050781) | Cod sursa (job #1098024) | Cod sursa (job #2091012) | Cod sursa (job #2506612)
#include <stdio.h>
#define P 666013
#define MAXN 1000000
#define NIL 0
int in[P], next[MAXN];
int main() {
FILE *fin = fopen( "hashuri.in", "r" );
FILE *fout = fopen( "hashuri.out", "w" );
int n, i, op, x, nr, ant;
fscanf( fin, "%d", &n );
for ( i = 0; i < n; ++i ) {
fscanf( fin, "%d%d", &op, &x );
switch( op ) {
case 1:
nr = in[x % P];
while ( nr != NIL && nr != x ) {
nr = next[nr];
}
if ( nr == NIL ) {
next[x] = in[x % P];
in[x % P] = x;
}
break;
case 2:
nr = in[x % P];
ant = NIL;
while ( nr != NIL && nr != x ) {
ant = nr;
nr = next[nr];
}
if ( nr == x && ant != NIL ) {
next[ant] = next[next[ant]];
} else if ( ant == NIL ) {
in[x % P] = next[nr];
next[in[x % P]] = next[next[nr]];
}
break;
case 3:
nr = in[x % P];
while ( nr != NIL && nr != x ) {
nr = next[nr];
}
if ( nr == NIL ) {
fprintf( fout, "0\n" );
} else {
fprintf( fout, "1\n" );
}
break;
}
}
fclose( fin );
fclose( fout );
return 0;
}