Cod sursa(job #2859685)

Utilizator elenacurecheriuElena Curecheriu elenacurecheriu Data 1 martie 2022 19:11:12
Problema Heapuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <queue>
using namespace std;

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

int n, nr_elem, v[250005], op;
bool used[250005];
long long k;

struct min_heap
{
    int ind;
    inline bool operator < (const min_heap &other) const
    {
        return v[ind] > v[other.ind];
    }
};

priority_queue <min_heap> heap;
int main()
{
    fin>>n;
    while(n--)
    {
        fin>>op;
        if(op==1)
        {
            fin>>k;
            v[++nr_elem]=k;
            used[nr_elem]=1;
            heap.push({nr_elem});
        }
        if(op==2)
        {
            fin>>k;
            used[k]=0;
        }
        if(op==3)
        {
            while(!used[heap.top().ind])
                heap.pop();
            fout<<v[heap.top().ind]<<'\n';
        }
    }
    return 0;
}