Cod sursa(job #1244548)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 17 octombrie 2014 18:58:47
Problema Heapuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include<fstream>
#include<queue>

using namespace std;

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

const int nmax = 200000;
const int inf = 1 << 30;
int v[ nmax + 1 ];

struct cmp {
    bool operator()( int x, int y ) {
        return v[ x ] > v[ y ];
    }
};
priority_queue <int, vector<int>, cmp> h;

int main() {
    int n, t, ii, x;
    fin >> n;
    ii = 0;
    for( int i = 0; i < n; ++ i ) {
        fin >> t;
        if ( t == 3 ) {
            while ( v[ h.top() ] == inf ) {
                h.pop();
            }
            fout << v[ h.top() ] << "\n";
        } else if ( t == 1 ) {
            fin >> v[ ii ];
            h.push( ii );
            ++ ii;
        } else {
            fin >> x;
            v[ x - 1 ] = inf;
        }
    }
    fin.close();
    fout.close();
    return 0;
}