Cod sursa(job #640487)

Utilizator vendettaSalajan Razvan vendetta Data 25 noiembrie 2011 21:26:21
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include <fstream>
#include <vector>
#define MOD 666013

using namespace std;

int n;
vector<int> t_hash[MOD];
typedef vector<int>::iterator it;

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

void citeste(){

    f>>n;

}

it afla_iterator(int x){

    int h_x = x % MOD;


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

    return t_hash[h_x].end();

}

void sterge(int x){

    it ite = afla_iterator(x);
    int h_x = x % MOD;

        if (ite != t_hash[h_x].end())
            t_hash[h_x].erase(ite);

}

void adauga(int x){

    it ite = afla_iterator(x);
    int h_x = x % MOD;

    if (ite == t_hash[h_x].end())
        t_hash[h_x].push_back(x);

}

void rezolva(){

    for(int i=1; i<=n; ++i){
        int x,y;
        f>>x>>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) == t_hash[h_x].end())
                g<<"0"<<"\n";
            else g<<"1"<<"\n";
        }
    }

}

int main(){

    citeste();
    rezolva();

    f.close();
    g.close();

    return 0;

}