Cod sursa(job #2815934)

Utilizator TudosieRazvanTudosie Marius-Razvan TudosieRazvan Data 10 decembrie 2021 17:17:47
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.31 kb
#include <fstream>
#include <map>
#include <algorithm>
using namespace std;

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

int n;
std::unordered_map< int , int > v;

int main()
{
    fin>>n;
    for(int i=1; i<=n; i++)
    {
        int cer;
        fin>>cer;
        switch(cer)
        {
        case(1):
        {
            int x;
            fin>>x;
            map<int,int>::iterator poz=v.find(x);
            if(poz==v.end())
            {
                v.insert({x,1});
            }
            else
            {
                poz->second++;
            }
            break;
        }
        case(2):
        {
            int x;
            fin>>x;
            map<int,int>::iterator poz=v.find(x);
            if(poz!=v.end())
            {
                poz->second--;
                if(poz->second==0)
                {
                    v.erase(x);
                }
            }
            break;
        };
        case(3):
        {
            int x;
            fin>>x;
            map<int,int>::iterator poz=v.find(x);
            if(poz==v.end())
            {
               fout<<"0\n";
            }
            else
            {
                fout<<"1\n";
            }
        };
        };
    }
    return 0;
}