Cod sursa(job #1123604)

Utilizator goalexboxerFMI Alexandru Ionascu goalexboxer Data 26 februarie 2014 09:17:52
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include<fstream>
#include<vector>

#define FIN "hashuri.in"
#define FOUT "hashuri.out"
#define MOD 666013
using namespace std;

ifstream f(FIN);
ofstream g(FOUT);

vector<int> h[MOD];
int n;

vector<int>::iterator hash_find(int x)
{
    int list = x % MOD;
    vector<int>::iterator it;
    for(it=h[list].begin();it!=h[list].end();it++)
    {
        if(*it == x)
        {
            return it;
        }
    }

    return h[list].end();
}

void hash_insert(int x)
{
    int list = x % MOD;

    if(hash_find(x) == h[list].end())
        h[list].push_back(x);

}

void hash_erase(int x)
{
    int list = x % MOD;
    vector<int>::iterator it = hash_find(x);
     if(it != h[list].end())
        h[list].erase(it);

}

int main()
{
    int x,y;
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>x;
        f>>y;

        switch(x)
        {
            case 1:
                hash_insert(y);
                break;
            case 2:
                hash_erase(y);
                break;
            case 3:
                g<<(hash_find(y)!=h[y%MOD].end())<<endl;
                break;
        }
    }

    return 0;
}