Cod sursa(job #3343926)

Utilizator Dragu_AndiDragu Andrei Dragu_Andi Data 28 februarie 2026 18:50:19
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("heapuri.in");
ofstream fout("heapuri.out");

struct heapnode{
    int val;
    int cnt;
    bool operator < (const heapnode &other) const{
        return val > other.val;
    }
};

const int nmax=2e5;
int n;
priority_queue<heapnode> heap;
bool deleted[nmax];

int main()
{
    fin >> n;
    int c, x, cont=1;
    for(int i=0; i<n; i++)
    {
        fin >> c;
        if(c==3)
        {
            while(deleted[heap.top().cnt])
                heap.pop();
            fout << heap.top().val << '\n';
        }
        else
        {
            fin >> x;
            if(c==1)
                heap.push({x,cont++});
            else
                deleted[x]=true;
        }
    }
    return 0;
}