Cod sursa(job #1492869)

Utilizator Vally77FMI Calinescu Valentin Gelu Vally77 Data 28 septembrie 2015 12:29:52
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <fstream>
#include <set>
using namespace std;
ifstream ka("hashuri.in");
ofstream ki("hashuri.out");
const int MOD = 666013;
int n, c, x;
set <int> numere[MOD + 1];

bool cauta(int t)
{
    bool gasit = false;
    for(set<int>::iterator it = numere[t % MOD].begin(); it != numere[t % MOD].end() && !gasit; ++it)
        if(*it == x)
            gasit = true;
    return gasit;
}

int main()
{
    ka >> n;
    for(int i = 1; i <= n; i++)
    {
        ka >> c >> x;
        if(c == 1)
            numere[x % MOD].insert(x);
        else if(c == 2)
            numere[x % MOD].erase(x);
        else
        {
            if(cauta(x))
                ki << 1 << '\n';
            else
                ki << 0 << '\n';
        }
    }
}