Pagini recente » Cod sursa (job #713169) | Cod sursa (job #499872) | Cod sursa (job #1303679) | Cod sursa (job #2077249) | Cod sursa (job #1763733)
#include <stdio.h>
#define nmax 1000000
#define mod 702113
struct hashuri{
int val, next;
}v[nmax];
int lasthash[mod];
inline void adauga( int poz, int nr ){
v[poz].val = nr; ///adaugam elementul in vectorul de valori
v[poz].next = lasthash[nr%mod]; ///memoram in lista pozitia ultimului element cu acest cod hash
lasthash[nr%mod] = poz; ///stocam ultima pozitie a nr cu acel hash
}
int cauta( int nr ){
int poz = lasthash[ nr%mod ];
while( poz!=0 && v[poz].val!=nr )
poz = v[poz].next;
return (poz>0);
}
inline void sterge( int nr ){
int poz;
poz = lasthash[nr%mod];
if( v[poz].val==nr )
lasthash[nr%mod] = v[poz].next;
else{
while( v[ v[poz].next ].val!=nr && v[poz].next!=0 )
poz = v[poz].next;
if( v[v[poz].next].val==nr)
v[poz].next = v[ v[poz].next ].next;
}
}
int main()
{
int n, i, ver, nr;
FILE *fin, *fout;
fin = fopen( "hashuri.in", "r" );
fout = fopen( "hashuri.out", "w" );
fscanf( fin, "%d", &n );
for( i=1; i<=n; i++ ){
fscanf( fin, "%d%d", &ver, &nr );
if( ver==1 ){
if( cauta(nr)== 0 )
adauga( i, nr );
}
else if( ver==2 ){
sterge(nr);
}
else
fprintf( fout, "%d\n", cauta(nr) );
}
fclose( fin );
fclose( fout );
return 0;
}