Cod sursa(job #2223158)

Utilizator Luca19Hritcu Luca Luca19 Data 19 iulie 2018 11:15:23
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <fstream>
#include <queue>

using namespace std;

ifstream f("heapuri.in");
ofstream g("heapuri.out");

struct heap
{
    int val, poz;
    bool operator<(const heap &x)  const
    {
         return val > x.val;
    }
};
priority_queue <heap> v;
char exista[200005];
int n, tip, x, p;
int main()
{
     f >> n;
     for (int i = 1; i <= n; i ++ )
     {
         f >> tip;
         if (tip == 1)
         {
             f >> x;
            v.push({x,++p});
         }
         else
        if (tip == 2)
        {
             f >> x;
            exista[x]=1;
        }
        else
        if (tip == 3)
        {
            while (!v.empty() && exista[v.top().poz])
                v.pop();
            g<<v.top().val<<'\n';
        }
    }
    return 0;
}