Cod sursa(job #1112403)

Utilizator techLaurentiu Avasiloaie tech Data 19 februarie 2014 19:09:49
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.36 kb
#include <fstream>
#include <vector>
#include <algorithm>
#define modulo 666013

using namespace std;

ifstream in ( "hashuri.in" ) ;
ofstream out ( "hashuri.out" ) ;

vector<int> vect[modulo] ;

int n , tip , nr , i ;

int hash_function ( int nr )
{
    return ( 31*nr + 951 ) % modulo ;
}

void insert_function ( int nr )
{
    int key = hash_function(nr) ;

    if ( std::find( vect[key].begin() , vect[key].end() , nr ) != vect[key].end() ) { ; }
    else { vect[key].push_back(nr) ; }
}

void erase_function ( int nr )
{
    int key = hash_function(nr) ;

    if ( std::find( vect[key].begin() , vect[key].end() , nr ) != vect[key].end() )
    {
        vect[key].erase( std::remove( vect[key].begin() , vect[key].end() , nr ) , vect[key].end() ) ;
    }
}

void call_function ( int nr )
{
    int key = hash_function(nr) ;

    if ( std::find( vect[key].begin() , vect[key].end() , nr ) != vect[key].end() ) { out << 1 << "\n" ; }
    else { out << 0 << "\n" ; }
}

int main()
{
    in >> n ;

    for ( i = 1 ; i <= n ; i ++ )
    {
        in >> tip >> nr ;

        if ( tip == 1 )
        {
            insert_function(nr) ;
        }

        else if ( tip == 2 )
        {
            erase_function(nr) ;
        }

        else
        {
            call_function(nr) ;
        }
    }

    return 0;
}