Cod sursa(job #1804793)

Utilizator TudorVersoiuVersoiu Tudor Sorin TudorVersoiu Data 12 noiembrie 2016 23:41:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.19 kb
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <set>

#define MOD 666667

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

vector<int> table[MOD];



inline void addElem(int x) {
    int poz = x%MOD;
    vector<int>::iterator it = find(table[poz].begin(), table[poz].end(), x);

    if ( it == table[poz].end() )
        table[poz].push_back(x);
}
void delElem(int x) {
    int poz = x%MOD;
    vector<int>::iterator it = find(table[poz].begin(), table[poz].end(), x);

    if ( it != table[poz].end() )
        table[poz].erase(it);
}

inline void queryElem(int x) {
    int poz = x%MOD;
    vector<int>::iterator it = find(table[poz].begin(), table[poz].end(), x);

    if ( it != table[poz].end() )
        g << 1 << '\n';
    else
        g << 0 << '\n';
}

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;
        }
    }
}