Cod sursa(job #3132174)

Utilizator fanevodaCalota Stefan fanevoda Data 21 mai 2023 23:44:55
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <fstream>
#include <vector>

std::ifstream in("hashuri.in");
std::ofstream out("hashuri.out");

int n;
const int M = 666013;

std::vector<int> map[M];


int gasit(int x)
{
    for (int i = 0; i < map[x % M].size(); i++)
        if (map[x % M][i] == x)
            return i;
    return -1;
}

void minus(int x)
{
    if (gasit(x) != -1)
        map[x % M].erase(map[x % M].begin() + gasit(x));
}

void bagat(int x)
{
    if (gasit(x) == -1)
        map[x % M].push_back(x);
}

int main()
{
    in >> n;

    int x, op;

    for (int i = 0; i < n; i++)
    {
        in >> op >> x;

        switch (op)
        {
        case 1:
            bagat(x);
            break;
        case 2:
            minus(x);
            break;
        case 3:
            out << (gasit(x) != -1) << std::endl;
            break;
        }

    }
}