Cod sursa(job #1994613)

Utilizator vlasiuflaviusVlasiu Flavius vlasiuflavius Data 25 iunie 2017 15:03:09
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <fstream>
#include <vector>
#define mod 666013
using namespace std;
ofstream fout("hashuri.out");
ifstream fin("hashuri.in");
int n,i,a,b;
vector< int > v[1234580];
inline vector< int >::iterator cautaval( int x )
{
    int aux = x % mod;
    vector< int >::iterator it;
    for( it = v[ aux ].begin() ; it != v[ aux ].end() ; it++ )
        if( *it == x )
            return it;
    return v[ aux ].end();
}
void insereaza( int x )
{
    int aux = x % mod;
    auto it = cautaval( x );
    if( it == v[ aux ].end() )
        v[ aux ].push_back( x );
}
void sterge( int x )
{
    int aux = x % mod;
    auto it = cautaval( x );
    if( it != v[ aux ].end() )
        v[ aux ].erase( it );
}
bool cauta( int x )
{
    int aux = x % mod;
    auto it = cautaval( x );
    return ( it != v[ aux ].end() ) ;
}
int main()
{
    fin>>n;
    for( i = 1 ; i <= n ; i++ )
    {
        fin>>a>>b;
        if( a == 1 )
            insereaza( b );
        if( a == 2 )
            sterge( b );
        if( a == 3 )
            fout<<cauta( b )<<'\n';
    }
}