Cod sursa(job #1807937)

Utilizator OFY4Ahmed Hamza Aydin OFY4 Data 17 noiembrie 2016 09:13:50
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <fstream>
#include <queue>

using namespace std;

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

const int Max = 200010;

struct heap
{
    int x, ind;
    bool operator <(const heap &aux) const
    {
        return x > aux.x;
    }
};

priority_queue<heap> h;
char vaz[Max];

int main()
{
    int n, tur, x, cnt = 0;
    in >> n;

    for(int i = 1; i <= n ;++i)
    {
        in >> tur;
        switch(tur)
        {
            case 1:
                in >> x;
                h.push({x,++cnt});
                break;
            case 2:
                in >> x;
                vaz[x] = 1;
                break;
            case 3:
                while(!h.empty() && vaz[h.top().ind])
                    h.pop();
                out << h.top().x << "\n";
                break;
        }
    }
}