Cod sursa(job #1548885)

Utilizator Emy1337Micu Emerson Emy1337 Data 11 decembrie 2015 16:35:06
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.23 kb
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int MOD = 666013; // to do verificam pe infoarena cum merge si cu alte valori
vector < int > hashuri[MOD];


int get_hash(int x) {
    return x%MOD;
}

void add(int x)
{
    int y=get_hash(x);
    int found=0;

    for (auto it : hashuri[y])
        if(it==x){
            found=1;
            break;
        }


    if(!found)
        hashuri[y].push_back(x);


}

void del(int x)
{
    int y=get_hash(x);
    for (auto it = hashuri[y].begin(); it != hashuri[y].end(); ++it)
        if (*it == x) {
            hashuri[y].erase(it);
            return;
        }
}

int exist(int x)
{
    int y=get_hash(x);
    for (auto it : hashuri[y])
        if(it==x)
            return 1;

    return 0;
}




int main()
{
    int n;
    fin>>n;
    for(int i=1; i<=n; i++)
    {
        int tip,val;
        fin>>tip>>val;
        if(tip==1)
        {
            add(val);
        }
        else if(tip==2)
        {
            del(val);
        }
        else
        {
            fout<<exist(val)<<"\n";
        }
    }
    return 0;
}