Cod sursa(job #2747061)

Utilizator Pop_MariaPop Maria Pop_Maria Data 28 aprilie 2021 19:58:03
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
#define numar 500009

using namespace std;

int n, op, x;

vector <int> v[numar];

int operatie_tip_3(int a)
{
    int list = a % numar;

    for(unsigned int i = 0; i < v[list].size(); i++)
        if(v[list][i] == a)
            return 1;

    return 0;
}

void operatie_tip_1(int a)
{
    int list = a % numar;

    if(operatie_tip_3(a) == 0)
        v[list].push_back(a);
    else
        return;
}

void operatie_tip_2(int a)
{
    int list = a % numar;

    for(unsigned int i = 0; i < v[list].size(); i++)
        if(v[list][i] == a)
        {
            v[list].erase(v[list].begin() + i);
            break;
        }
}

int main()
{
    ifstream fin("hashuri.in");
    ofstream fout("hashuri.out");

    fin >> n;

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

        if(op == 1)
            operatie_tip_1(x);
        else if(op == 2)
            operatie_tip_2(x);
        else
            fout << operatie_tip_3(x) << '\n';
    }
    return 0;
}