Cod sursa(job #1566281)

Utilizator pulseOvidiu Giorgi pulse Data 11 ianuarie 2016 22:45:36
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <fstream>
#include <vector>

using namespace std;

#define MOD 666013

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

vector <int> H[MOD];

vector <int> :: iterator isHash(int x)
{
    vector <int> :: iterator it;
    int pos = x % MOD;

    for (it = H[pos].begin(); it != H[pos].end(); ++it)
        if (*it == x) break;

    return it;
}

void delHash(int x)
{
    vector <int> :: iterator it = isHash(x);
    int pos = x % MOD;

    if (it == H[pos].end()) // nu l-am gasit
        return;

    H[pos].erase(it);
}

void insHash(int x)
{
    int pos = x % MOD;

    if (isHash(x) != H[pos].end()) // l-am gasit
        return;

    H[pos].push_back(x);
}

int main()
{
    int m, tip, x;

    fin >> m;
    while (m--)
    {
        fin >> tip >> x;
        if (tip == 1)
            insHash(x);
        else if (tip == 2)
            delHash(x);
        else
            fout << (isHash(x) != H[x % MOD].end()) << '\n';
    }

    return 0;
}