Cod sursa(job #1461491)

Utilizator CollermanAndrei Amariei Collerman Data 15 iulie 2015 20:08:51
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ofstream fout("hashuri.out");
ifstream fin("hashuri.in");
const int MOD = 666013; // a.k.a the satanico-illuminati number

int n, op, x;
vector<int> Hash[MOD];

int get()
{
    int poz = x % MOD;
    auto it = find(Hash[poz].begin(), Hash[poz].end(), x);

    if(it != Hash[poz].end()) return 1;
    return 0;
}

void add()
{
    int poz = x % MOD;
    auto it = find(Hash[poz].begin(), Hash[poz].end(), x);

    if(it == Hash[poz].end()) Hash[poz].push_back(x);
}

void del()
{
    int poz = x % MOD;
    auto it = find(Hash[poz].begin(), Hash[poz].end(), x);

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

int main()
{
    fin >> n;
    for(int i=1; i<=n; i++)
    {
        fin >> op >> x;
        switch(op)
        {
            case 1: { add(); break; }
            case 2: { del(); break; }
            case 3: { fout << get() << '\n'; break; }
        }
    }
    return 0;
}