Cod sursa(job #2263269)

Utilizator alexge50alexX AleX alexge50 Data 18 octombrie 2018 15:47:56
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 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++)
    {
        static std::function<void()> v[] = {
                [&](){
                    int x;
                    fin >> x;

                    history.push_back(x);

                    m[x]++;
                },

                [&](){
                    int x;
                    fin >> x;

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

                    if(it->second == 0)
                        m.erase(it->first);
                },

                [&](){
                    fout << m.begin()->first << std::endl;
                },
        };

        int c;
        fin >> c;

        v[c - 1]();
    }

    return 0;
}