Cod sursa(job #1804640)

Utilizator TudorVersoiuVersoiu Tudor Sorin TudorVersoiu Data 12 noiembrie 2016 20:45:43
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <cstring>
#include <set>


#define HASH_SIZE 1000000

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

int hashFunction(int x) {
    return x/666667;
}

set<int> table[666667];

void addElem(int x) {
    int poz = hashFunction(x);

    table[poz].insert(x);
}
void delElem(int x) {
    int poz = hashFunction(x);

    table[poz].erase(x);
}

bool queryElem(int x) {
    int poz = hashFunction(x);

    if ( table[poz].find(x) == table[poz].end() ) {
        g << 0 << '\n';
        return 0;
    } else {
        g << 1 << '\n';
        return 1;
    }
}

int NrOperatii;

int main()
{
    f >> NrOperatii; int op, x;

    for ( int i=1; i<=NrOperatii; i++ )
    {
        f >> op >> x;

        switch ( op )
        {
            case 1: addElem(x);     break;
            case 2: delElem(x);     break;
            case 3: queryElem(x);   break;
        }
    }
}