Cod sursa(job #1969433)

Utilizator waren4Marius Radu waren4 Data 18 aprilie 2017 14:24:46
Problema Heapuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

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

priority_queue <pair <int,int> > q;

int n, c, nr; bool a[200005];

pair <int,int> k;

int main() {
    int i;
    f>>n;
    nr = 0;
    for(i = 1; i <= n; ++i) {
        f>>c;
        if (c == 1) {
            f>>k.first;
            k.first = -k.first;
            ++nr;
            k.second = nr;
            q.push(k);
        }
        if (c == 2) {
            f>>k.first;
            a[k.first] = 1;
        }
        if (c == 3) {
            while(a[q.top().second]) {
                q.pop();
            }
            g<<-q.top().first;
        }
    }
    return 0;
}