Cod sursa(job #1920361)

Utilizator george_stelianChichirim George george_stelian Data 9 martie 2017 23:45:49
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <cstdio>
#include <queue>

using namespace std;

struct heap
{
    int x,poz;
    bool operator <(const heap &aux) const
    {
        return x>aux.x;
    }
};
priority_queue<heap> h;
char vaz[200010];

int main()
{
    freopen("heapuri.in", "r", stdin);
    freopen("heapuri.out", "w", stdout);
    int n,nr=0,tip,x;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&tip);
        if(tip==1)
        {
            scanf("%d",&x);
            nr++;
            h.push({x,nr});
        }
        else if(tip==2)
        {
            scanf("%d",&x);
            vaz[x]=1;
        }
        else
        {
            while(vaz[h.top().poz]) h.pop();
            printf("%d\n",h.top().x);
        }
    }
    return 0;
}