Cod sursa(job #640726)

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

using namespace std;

vector<int> lista[MOD + 5];
typedef vector<int>::iterator it;
char c;
char s[10000000];
int n, poz, l;

void citeste( int &x, int &poz ){

    x = 0;

    while (s[poz] <'0' || s[poz] > '9')
        ++poz;

    while (poz <= l && s[poz] != ' '){
        x += s[poz] - '0';
        x *= 10;
        ++poz;
    }

    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 );

    scanf("%d\n", &n);

    for(int i=1; i<=n; ++i){
        int x=0, y=0;
        gets(s);
        l = strlen(s);
        --l;
        poz = 0;
        while (s[poz] != ' '){
            x += s[poz] - '0';
            x *= 10;
            ++poz;
        }
        x /= 10;
        ++poz;
        while (poz <= l){
            y += s[poz] - '0';
            y *= 10;
            ++poz;
        }
        y /= 10;
        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;

}