Cod sursa(job #1952587)

Utilizator jurjstyleJurj Andrei jurjstyle Data 4 aprilie 2017 11:15:30
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

const int mod1 = 777013, mod2 = 666013;
int V[mod1 + 1], V2[mod2 + 1];
int N;

void inserare(int x)
{
    int ind1 = x % mod1;
    int ind2 = x % mod2;
    if (V[ind1] == 0 && V2[ind2] == 0)
        V[ind1] = V2[ind2] = 1;
}
void stergere(int x)
{
    int ind1 = x % mod1;
    int ind2 = x % mod2;
    V[ind1] = V2[ind2] = 0;
}

int main()
{
    f >> N;
    for (; N--;)
    {
        int op, x;
        f >> op >> x;
        if (op == 1)
            inserare(x);
        else if (op == 2)
            stergere(x);
        else
            g << (V[x % mod1] && V2[x % mod2]) << "\n";
    }
    f.close();
    g.close();
}