Cod sursa(job #1921132)

Utilizator jason2013Andronache Riccardo jason2013 Data 10 martie 2017 11:30:10
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include<bits/stdc++.h>
using namespace std;

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

const int N_MAX = 2e5 + 2;
bool deleteElement[N_MAX];

priority_queue< pair<int, int>, vector<pair <int, int> >, greater< pair<int, int> > > Q;

int main()
{
    int N, test, x, l;
    in >> N;
    l = 0;
    while( N-- )
    {
        in >> test;
        if( test == 1 ){
            in >> x;
            l ++;
            Q.push({x, l});
        }else{
            if( test == 2 )
            {
                in >> x;
                deleteElement[x] = 1;
            }else{
                while( deleteElement[ Q.top().second ] ) Q.pop();
                out << Q.top().first <<"\n";
            }
        }
    }
    return 0;
}