Pagini recente » Cod sursa (job #2524049) | Cod sursa (job #781154) | Cod sursa (job #2451098) | Cod sursa (job #3246353) | Cod sursa (job #1520597)
#include <cstdio>
#include <vector>
using namespace std;
FILE *f = fopen ( "hashuri.in" , "r" ) , *g = fopen ( "hashuri.out" , "w" );
const int MAX = 666015;
int i , N , type , request;
vector < int > Hash [ MAX ];
int HashFunction ( int number )
{
return ( number % 666013 ) ;
}
void add ( int number )
{
int value = HashFunction ( number );
Hash [ value ] . push_back ( number );
}
void remove ( int number )
{
int value = HashFunction ( number );
for ( i = 0 ; i < Hash [ value ] . size () ; i ++ )
if ( Hash [ value ] [ i ] == number )
Hash [ value ] [ i -- ] = Hash [ value ] [ Hash [ value ] . size () - 1 ] , Hash [ value ] . pop_back () ;
}
int isIn ( int number )
{
int value = HashFunction ( number );
for ( i = 0 ; i < Hash [ value ] . size () ; i ++ )
if ( Hash [ value ] [ i ] == number )
return 1;
return 0;
}
void read()
{
fscanf ( f , "%d" , &N );
for ( ; N ; N -- )
{
fscanf ( f , "%d %d" , &type , &request );
if ( type == 1 ) //add request to the hash
add ( request );
else
if ( type == 2 ) //remove request from the hash
remove ( request );
else //check to see if request is in hash or not
fprintf ( g , "%d\n" , isIn ( request ) );
}
}
int main()
{
read();
return 0;
}