Cod sursa(job #3168363)

Utilizator Dragu_AndiDragu Andrei Dragu_Andi Data 12 noiembrie 2023 11:53:29
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <fstream>
#include <queue>

using namespace std;

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

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

const int nmax=2e5 + 1;
bool removed[nmax];

int main()
{
    priority_queue<elem> heap;
    int n;
    fin >> n;
    int op, x, cnt=1;
    for(int i=0; i<n; i++)
    {
        fin >> op;
        if(op==1)
        {
            fin >> x;
            heap.push(elem(x, cnt++));
        }
        else if(op==2)
        {
            fin >> x;
            removed[x]=1;
        }
        else
        {
            while(removed[heap.top().poz]) heap.pop();
            fout << heap.top().val << '\n';
        }
    }
    return 0;
}