Cod sursa(job #2892795)

Utilizator 4N70N1U5Antonio Nitoi 4N70N1U5 Data 23 aprilie 2022 17:01:23
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define P 781853

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

int main()
{
    int n, op, val;
    
    std::vector< std::vector<int> > T(P);

    fin >> n;

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

        int pos = val % P;
        std::vector<int>::iterator it = std::find(T[pos].begin(), T[pos].end(), val);

        switch (op)
        {
        case 1:
            if (it == T[pos].end())
                T[pos].push_back(val);
            break;

        case 2:
            if (it != T[pos].end())
                T[pos].erase(it);
            break;

        case 3:
            if (it != T[pos].end())
                fout << "1\n";
            else
                fout << "0\n";
            break;
        
        default:
            break;
        }
    }
}