Cod sursa(job #3041374)

Utilizator stefanvoicaVoica Stefan stefanvoica Data 31 martie 2023 13:26:25
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin ("heapuri.in");
ofstream fout("heapuri.out");
int n,m;
bool viz[200002];

struct el
{
    int nr,poz;
    bool operator < (const el &other) const
    {
        return nr > other.nr;
    }
};
priority_queue<el>pq;

int main ()
{
    int op,x,y;
    fin>>m;

    while (m--)
    {
        fin>>op;
        if (op==3)
        {
            bool ok=0;
            while (ok==0)
            {
                el vf=pq.top();
                if (viz[vf.poz]==1)
                    pq.pop();
                else
                {
                    ok=1;
                    fout<<vf.nr<<'\n';
                }
            }

        }
        else
        {
            fin>>x;
            if (op==1)
                pq.push({x,++n});
            else    viz[x]=1;
        }
    }
}