Pagini recente » Cod sursa (job #2695791) | Cod sursa (job #1830472) | Cod sursa (job #2913078) | Cod sursa (job #83712) | Cod sursa (job #1110832)
#include <stdio.h>
#include <fstream>
#define modulo 10147003
#define hash_a 348191
#define hash_b 7653473
using namespace std;
ifstream in ( "hashuri.in" ) ;
struct node
{
unsigned long long value;
node *next ;
};
struct hash_table
{
bool used ;
node *next ;
};
hash_table vect[1000005] ;
node *p ;
unsigned long long x ;
int n , tip , i , y ;
void insert_hash ()
{
node *q ;
q = new node ; q->value = x ; q->next = NULL ;
if ( vect[y].used == 0 ) { vect[y].next = q ; vect[y].used = 1 ; }
else
{
p = vect[y].next ;
while ( p->next != NULL )
{
p = p->next ;
}
p->next = q ;
}
}
void delete_hash ()
{
if ( vect[y].used )
{
if ( vect[y].next->next == NULL )
{
vect[y].used = 0 ;vect[y].next = NULL ;
}
else
{
p = vect[y].next ;
while ( p->next->next != NULL )
{
p = p->next ;
}
p->next = NULL ;
}
}
}
void call_hash ()
{
if ( vect[y].used )
{
p = vect[y].next ;
while ( p->value != x )
{
p = p->next ;
}
printf ( "1\n" ) ;
}
else
{
printf ( "0\n" ) ;
}
}
int function_hash ()
{
return ( ( ( hash_a * x ) + hash_b ) % modulo ) % n ;
}
int main()
{
freopen ( "hashuri.out" , "w" , stdout ) ;
in >> n ;
for ( i = 1 ; i <= n ; i ++ )
{
in >> tip >> x ;
y = function_hash() ;
if ( tip == 1 ) { insert_hash() ; }
else if ( tip == 2 ) { delete_hash() ; }
else { call_hash() ; }
}
return 0;
}