Cod sursa(job #863206)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 23 ianuarie 2013 16:34:54
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.15 kb
#include<stdio.h>
#include<vector>
#define MOD 666013
using namespace std ;
vector < int > :: iterator it ;
vector < int > h [ MOD ] ;
vector < int > :: iterator find_x ( long x , long ind )
{
    for ( it = h [ ind ] . begin ( ) ; it != h [ ind ] . end ( ) ; ++ it )
        if ( * it == x )
            return it ;
    return h [ ind ] . end ( ) ;
}
void insert ( long x , long ind )
{
    it = find_x ( x , ind ) ;
    if ( it == h [ ind ] . end ( ) )
        h [ ind ] . push_back ( x ) ;
}
void erase ( long x , long ind )
{
    it = find_x ( x , ind ) ;
    if ( it != h [ ind ] . end ( ) )
        h [ ind ]. erase ( it ) ;
}
int main ( )
{
    long n ;
    freopen ( "hashuri.in" , "r" , stdin ) ;
    freopen ( "hashuri.out" , " w" , stdout ) ;
    scanf ( "%ld" , & n ) ;
    for ( long i = 1 ; i <= n ; ++ i )
    {
        long tip , x ;
        scanf ( "%ld %ld" , & tip , & x ) ;
        if ( tip == 1 )
            insert ( x , x % MOD ) ;
        if ( tip == 2 )
            erase ( x , x % MOD ) ;
        if ( tip == 3 )
            printf ( "%d\n" , find_x ( x , x % MOD ) != h [ x % MOD ] . end ( ) ) ;
    }
}