Cod sursa(job #2169286)

Utilizator zanugMatyas Gergely zanug Data 14 martie 2018 14:35:55
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <iostream>
#include <fstream>
#include <queue>

#include <cstdlib>

using namespace std;

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

const int NLIM = 2e5+10;

int n;
bool b[NLIM];

struct cucc
{
    int val, tim;
};

class compar
{
public:
    bool operator() (cucc a, cucc b)
    {
        return a.val > b.val;
    }
};


priority_queue < cucc, vector < cucc >, compar > heap;

int main()
{
    fin >> n;
    int i = 1;
    while(n--)
    {
        int t;
        fin >> t;

        if(t == 1)
        {
            cucc x;
            x.tim = i;
            ++i;
            fin >> x.val;
            heap.push(x);
        }
        else if(t == 2)
        {
            int x;
            fin >> x;
            b[x] = true;
        }
        else
        {
            while(b[heap.top().tim])
            {
                heap.pop();
            }
            fout << heap.top().val << "\n";
        }
    }

    return 0;
}