Cod sursa(job #640715)

Utilizator vendettaSalajan Razvan vendetta Data 26 noiembrie 2011 13:10:19
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.38 kb
#include <cstdio>
#include <vector>
#define MOD 666013

using namespace std;

vector<int> lista[MOD + 5];
typedef vector<int>::iterator it;
char c;
int n;

void citeste( int &x ){

    x = 0;

    scanf("%c", &c);

    while (c == ' ' && c != '\n') scanf("%c", &c);

    while ( c != ' ' && c !='\n'){
        x += c - '0';
        x *= 10;
        scanf("%c", &c);
    }

    x /= 10;

    return;

}

it afla_iterator(int x){

    int h_x = x % MOD;

    for(it i = lista[h_x].begin(); i != lista[h_x].end(); ++i){
        if (*i == x)
            return i;
    }

    return lista[h_x].end();

}

void adauga( int x ){

    int h_x = x % MOD;

    if (afla_iterator(x) == lista[h_x].end())
        lista[h_x].push_back(x);

}

void sterge( int x ){

    int h_x = x % MOD;

    it i = afla_iterator(x);

    if (i != lista[h_x].end())
        lista[h_x].erase(i);

}


int main(){

    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

    citeste( n );

    for(int i=1; i<=n; ++i){
        int x, y;
        citeste(x);
        citeste(y);
        if (x == 1){
            adauga( y );
        }else if (x == 2){
            sterge( y );
        }else if (x == 3){
            int h_x = y % MOD;
            if (afla_iterator(y) == lista[h_x].end()) printf("%d\n", 0);
                else printf("%d\n", 1);
        }
    }

    fclose(stdin);
    fclose(stdout);

    return 0;

}