Cod sursa(job #2218063)

Utilizator Anastasia11Susciuc Anastasia Anastasia11 Data 3 iulie 2018 11:22:44
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 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;
}