Cod sursa(job #2263270)

Utilizator alexge50alexX AleX alexge50 Data 18 octombrie 2018 15:50:13
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <fstream>
#include <vector>
#include <map>
#include <functional>

int main()
{
    std::ifstream fin("heapuri.in");
    std::ofstream fout("heapuri.out");
    int n;
    std::map<int, int> m;
    std::vector<int> history;

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

        if(c == 1)
        {
            int x;
            fin >> x;

            history.push_back(x);

            m[x]++;
        }
        else if (c == 2)
        {
            int x;
            fin >> x;

            auto it = m.find(history[x - 1]);
            it->second --;

            if(it->second == 0)
                m.erase(it->first);
        }
        else if (c == 3)
        {
            fout << m.begin()->first << std::endl;
        }
    }

    return 0;
}