Cod sursa(job #2374379)

Utilizator UnseenMarksmanDavid Catalin UnseenMarksman Data 7 martie 2019 18:16:11
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <fstream>
#include <queue>
using namespace std;

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

int n, cod, x, c;
bool ok[200002];
struct str{
    int x, pos;
    bool operator <(const str &other)const
    {
        return x>other.x;
    }
};
priority_queue<str>H;

int main()
{
    fin>>n;
    for(int i=1; i<=n; i++)
    {
        fin>>cod;
        if(cod==1)
        {
            fin>>x;
            c++;
            ok[c]=1;
            H.push({x,c});
        }
        else if(cod==2)
        {
            fin>>x;
            ok[x]=0;
            while(ok[H.top().pos]==0)
            {
                H.pop();
            }
        }
        else
        {
            fout<<H.top().x<<'\n';
        }
    }
}