Cod sursa(job #2531151)

Utilizator Tudor06MusatTudor Tudor06 Data 25 ianuarie 2020 19:07:19
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.16 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

const int MOD = 666013;

vector <int> v[MOD];

void add( int x ) {
    int j = x % MOD;
    vector<int>::iterator it;
    it = v[j].begin();
    while ( it != v[j].end() && *it != x ) {
        it ++;
    }
    if ( it == v[j].end() )
        v[j].push_back( x );
}
void sterge( int x ) {
    int j = x % MOD;
    vector<int>::iterator it;
    it = v[j].begin();
    while ( it != v[j].end() && *it != x ) {
        it ++;
    }
    if ( it != v[j].end() ) {
        v[j].erase( it );
    }
}
int cautare( int x ) {
    int j = x % MOD;
    vector<int>::iterator it;
    it = v[j].begin();
    while ( it != v[j].end() && *it != x ) {
        it ++;
    }
    return ( it != v[j].end() );
}

int main() {
    ifstream fin( "hashuri.in" );
    ofstream fout( "hashuri.out" );
    int n, i, cer, x;
    fin >> n;
    for ( i = 0; i < n; i ++ ) {
        fin >> cer >> x;
        if ( cer == 1 ) {
            add( x );
        } else if ( cer == 2 ) {
            sterge( x );
        } else
            fout << cautare( x ) << '\n';
    }
    return 0;
}