Cod sursa(job #3168370)

Utilizator Laura139Anghel Laura Laura139 Data 12 noiembrie 2023 12:01:45
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <fstream>
#include <queue>

using namespace std;

ifstream cin("heapuri.in");
ofstream cout("heapuri.out");

struct elem{
    int poz, val;
    bool operator<(const elem &other)const
    {
        return val>other.val;
    }
};

priority_queue <elem> heap;

int to_pop[200005];

int main()
{
    int n,k=1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int c,x;
        cin>>c;
        if(c==1)
        {
            cin>>x;
            elem e;
            e.val=x;
            e.poz=k;
            k++;
            heap.push(e);
        }
        if(c==2)
        {
            cin>>x;
            to_pop[x]=1;
        }
        if(c==3)
        {
            elem e=heap.top();
            while(to_pop[e.poz]==1)
            {
                heap.pop();
                e=heap.top();
            }
            cout<<heap.top().val<<'\n';
        }
    }
    return 0;
}