Cod sursa(job #1852519)

Utilizator DanielRusuDaniel Rusu DanielRusu Data 20 ianuarie 2017 21:13:39
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>

using namespace std;

#define DIM 200005

bitset <DIM> eliminated;
priority_queue <pair <int, int> > Q;

int main() {
    freopen("heapuri.in","r",stdin);
    freopen("heapuri.out","w",stdout);

    int N;

    scanf("%d\n", &N);

    int ord = 1;
    while(N--) {
        int op;
        scanf("%d", &op);

        if(op == 1) {
            int x;
            scanf("%d\n", &x);
            Q.push(make_pair(-x, ord++));
        }
        else {
            if(op == 2) {
                int x;
                scanf("%d\n", &x);
                eliminated[x] = 1;
            }
            else {
                cout << -Q.top().first << '\n';
            }
        }

        while(!Q.empty() && eliminated[Q.top().second]) {
            Q.pop();
        }
    }

    return 0;
}