Cod sursa(job #1111444)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 18 februarie 2014 21:21:34
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main() {
    ifstream cin("heapuri.in");
    ofstream cout("heapuri.out");
    priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > heap;
    vector<bool> erased;
    int q;
    cin >> q;
    for (int inserted = 0; q > 0; --q) {
        int type;
        cin >> type;
        if (type == 1) {
            int value;
            cin >> value;
            heap.push(make_pair(value, inserted++));
            erased.push_back(false);
        } else if (type == 2) {
            int index;
            cin >> index;
            erased[--index] = true;
        } else if (type == 3) {
            while (!heap.empty() && erased[heap.top().second])
                heap.pop();
            if (!heap.empty())
                cout << heap.top().first << "\n";
            else
                cout << "-1\n";
        }
    }
    cin.close();
    cout.close();
    return 0;
}