Cod sursa(job #2737875)

Utilizator RoberttoPopescu Paullo Robertto Karloss Robertto Data 5 aprilie 2021 11:36:14
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.16 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> v[666013];

int operatie_tip_3(int y, int cheie)
{
    for(int i = 0; i < v[cheie].size(); i++)
    {
        if(v[cheie][i] == y)
            return 1;
    }
    return 0;
}

void operatie_tip_2(int y, int cheie)
{
    for(int i = 0; i < v[cheie].size(); i++)
    {
        if(v[cheie][i] == y)
        {
            v[cheie].erase(v[cheie].begin() + i);
            break;
        }
    }
}

void operatie_tip_1(int y, int cheie)
{
    int ok = 0;
    for(int i = 0; i < v[cheie].size(); i++)
    {
        if(v[cheie][i] == y)
        {
            ok = 1;
            break;
        }
    }
    if(ok == 0)
        v[cheie].push_back(y);
}

int main()
{
    int x, y, n, cheie;
    f >> n; // numarul de operatii
    for(int i = 0; i < n; i++)
    {
        f >> x >> y; // citim tipul operatiei, si numarul
        cheie = y % 666013;
        if(x == 1)
            operatie_tip_1(y, cheie);
        else if(x == 2)
            operatie_tip_2(y, cheie);
        else
            g << operatie_tip_3(y, cheie) << '\n';
    }
    return 0;
}