Pagini recente » Cod sursa (job #201644) | Cod sursa (job #1070546)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const unsigned FNV_offset_basis = 2166136261;
const unsigned FNV_prime = 16777619;
const unsigned NR = 12;
const unsigned MASK = ( 1 << NR );
vector <unsigned> HT[MASK];
unsigned fhash( unsigned x )
{
unsigned hsh = FNV_offset_basis;
hsh = hsh ^ x;
hsh = hsh * FNV_prime;
return ( hsh & ( MASK - 1 ) );
}
bool find( unsigned value )
{
unsigned key = fhash( value );
for ( auto x: HT[key] )
if ( x == value )
return 1;
return 0;
}
void insert( unsigned value )
{
unsigned key = fhash( value );
if ( !find( value ) )
HT[key].push_back( value );
}
void erase( unsigned value )
{
unsigned key = fhash( value );
for ( vector<unsigned>::iterator x = HT[key].begin(); x != HT[key].end(); ++x )
if ( *x == value )
{
HT[key].erase( x );
break;
}
}
int N;
unsigned key, type;
const int DIM_BUFF = ( 1 << 20 );
char buffer[DIM_BUFF];
int position = DIM_BUFF;
char GetChar()
{
if ( position == DIM_BUFF )
{
fread( buffer, 1, DIM_BUFF, stdin );
position = 0;
}
return buffer[ position++ ];
}
unsigned rd()
{
unsigned nr = 0;
char c;
do
{
c = GetChar();
} while ( !isdigit( c ) );
do
{
nr = nr * 10 + ( c - '0' );
c = GetChar();
} while ( isdigit( c ) );
return nr;
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
N = rd();
while ( N-- )
{
type = rd(); key = rd();
if ( type == 1 ) insert( key );
if ( type == 2 ) erase( key );
if ( type == 3 ) printf("%d\n", find( key ) );
}
return 0;
}