Cod sursa(job #2272329)

Utilizator BogdanGhGhinea Bogdan BogdanGh Data 29 octombrie 2018 23:26:40
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("heapuri.in");
ofstream g("heapuri.out");
const int Nmax=2e5+10;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > heap;
int n,i,p,x,cnt;
bool used[Nmax];
int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>p;
        if(p==1)
        {
            f>>x;
            cnt++;
            heap.push({x,cnt});
        }
        else if(p==2)
        {
            f>>x;
            used[x]=true;
        }
        else {
            while(!heap.empty()&&used[heap.top().second])
                heap.pop();
            g<<heap.top().first<<'\n';
        }
    }
    return 0;
}