Cod sursa(job #2967054)

Utilizator pifaDumitru Andrei Denis pifa Data 18 ianuarie 2023 22:36:40
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.26 kb
#include <bits/stdc++.h>

using namespace std;

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

const int MOD = 666013;

vector <int> hsh[MOD + 1];

vector <int>::iterator gaseste(int x)
{
    int baza = x % MOD;
    for(vector <int>:: iterator it = hsh[baza].begin(); it != hsh[baza].end(); it++)
    {
        if(*it == x)
        {
            return it;
        }
    }
    return hsh[baza].end();
}

void insereaza(int x)
{
    int baza = x % MOD;
    if(gaseste(x) == hsh[baza].end())
    {
        hsh[baza].push_back(x);
    }
}

void sterge(int x)
{
    int baza = x % MOD;
    vector <int>:: iterator it = gaseste(x);
    if(it != hsh[baza].end())
    {
        hsh[baza].erase(it);
    }
}

int main()
{
    int q;
    in >> q;
    while(q--)
    {
        int op, x;
        in >> op >> x;
        if(op == 1)
        {
            insereaza(x);
        }
        if(op == 2)
        {
            sterge(x);
        }
        if(op == 3)
        {
            if(gaseste(x) != hsh[x % MOD].end())
            {
                out << 1 << ' ';
            }
            else
            {
                out << 0 << ' ';
            }
            out << '\n';
        }
    }
    return 0;
}