Cod sursa(job #1787071)

Utilizator grimmerFlorescu Luca grimmer Data 24 octombrie 2016 09:00:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.35 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int MOD = 666013;
int n;
vector<int> hs[MOD + 5];

vector<int> :: iterator search_val(int val){
    int new_val, i;
    new_val = val % MOD;

    for(i = 0; i < (int)hs[new_val].size(); ++i){
        if(hs[new_val][i] == val){
            return hs[new_val].begin() + i;
        }
    }

    return hs[new_val].end();
}

void add(int x){
    int new_val;
    new_val = x % MOD;

    if(search_val(x) == hs[new_val].end()){
        hs[new_val].push_back(x);
    }

}

void del(int x){
    int new_val;
    new_val = x % MOD;
    vector<int> :: iterator curr_pos = search_val(x);

    if(curr_pos != hs[new_val].end()){
        hs[new_val].erase(curr_pos);
    }

}

int main()
{
    int i, type, x, new_val;
    fin>>n;

    for(i = 1; i <= n; ++i){
        fin>>type>>x;
        new_val = x % MOD;

        if(type == 1){
            add(x);
        }
        else{
            if(type == 2){
                del(x);
            }
            else{
                if(search_val(x) != hs[new_val].end()){
                    fout<<"1"<<"\n";
                }
                else{
                    fout<<"0"<<"\n";
                }
            }
        }
    }

    return 0;
}