Cod sursa(job #2246607)

Utilizator crion1999Anitei cristi crion1999 Data 27 septembrie 2018 11:39:44
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <queue>
#include <fstream>
#include <iostream>
#include <functional>
using namespace std;

priority_queue<pair<int, int>, vector<pair<int, int > >, greater<pair<int, int> > > pq;
bool erased[200001];
ifstream fi("heapuri.in");
ofstream fo("heapuri.out");

int main()
{
    int command, n, val, order = 0;
    fi >> n;
    while(n--)
    {
        fi >> command;

        if(command == 1)
        {
            fi >> val;
            order++;
            pq.push({val,order});

        }
        else if(command == 2)
        {
            fi >> val;
            erased[val] = 1;
        }
        else if(command == 3)
        {
            while(!pq.empty() && erased[pq.top().second])
                pq.pop();

            if(!pq.empty())
                fo << pq.top().first<<"\n";
        }
    }
}