Cod sursa(job #3040664)

Utilizator IvanAndreiIvan Andrei IvanAndrei Data 30 martie 2023 11:14:27
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.32 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int mod = 666013;

vector <int> hsh[mod];

void ins (int x)
{
    int baza = x % mod;
    bool ok = false;
    for (auto f : hsh[baza])
    {
        if (f == x)
        {
            ok = true;
            break;
        }
    }
    if (!ok)
    {
        hsh[baza].push_back(x);
    }
}

void del (int x)
{
    int baza = x % mod;
    vector <int> :: iterator it = hsh[baza].begin();
    while (it != hsh[baza].end())
    {
        if (*it == x)
        {
            hsh[baza].erase(it);
            return;
        }
        it++;
    }
}

int query (int x)
{
    int baza = x % mod;
    vector <int> :: iterator it = hsh[baza].begin();
    while (it != hsh[baza].end())
    {
        if (*it == x)
        {
            return 1;
        }
        it++;
    }
    return 0;
}

int main ()
{
    int q;
    in >> q;
    while (q--)
    {
        int op, x;
        in >> op >> x;
        if (op == 1)
        {
            ins(x);
        }
        if (op == 2)
        {
            del(x);
        }
        if (op == 3)
        {
            out << query(x) << '\n';
        }
    }
    in.close();
    out.close();
    return 0;
}