Cod sursa(job #1952598)

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

using namespace std;

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

const int mod1 = 777013;
const int mod2 = 666013;
vector <int> G1[mod1 + 1], G2[mod2 + 1];
int N;

void inserare(int x)
{
    int ind1 = x % mod1;
    int ind2 = x % mod2;
    if (find(G1[ind1].begin(), G1[ind1].end(), x) == G1[ind1].end() && find(G2[ind2].begin(), G2[ind2].end(), x) == G2[ind2].end())
        G1[ind1].push_back(x), G2[ind2].push_back(x);
}
void stergere(int x)
{
    int ind1 = x % mod1;
    int ind2 = x % mod2;
    vector <int> :: iterator it = find(G1[ind1].begin(), G1[ind1].end(), x);
    vector <int> :: iterator it2 = find(G2[ind2].begin(), G2[ind2].end(), x);
    if (it != G1[ind1].end() && it2 != G2[ind2].end())
        G1[ind1].erase(it), G2[ind2].erase(it2);
}


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 << ((find(G1[x % mod1].begin(), G1[x % mod1].end(), x) != G1[x % mod1].end()) && (find(G2[x % mod2].begin(), G2[x % mod2].end(), x) != G2[x % mod2].end())) << "\n";
    }
    f.close();
    g.close();
}