Cod sursa(job #1929215)

Utilizator bciobanuBogdan Ciobanu bciobanu Data 17 martie 2017 12:15:31
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <bits/stdc++.h>

using namespace std;

int main(void) {
    ifstream cin("heapuri.in");
    ofstream cout("heapuri.out");
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int q;
    cin >> q;
    
    priority_queue<int> Heap, Erased;
    vector<int> Elements;
    while(q--> 0) {
        int type;
        cin >> type;
        if(type == 1) {
            int x;
            cin >> x;
            Elements.push_back(x);
            Heap.push(-x);
        } else if(type == 2) {
            int idx;
            cin >> idx;
            Erased.push(-Elements[idx - 1]);
        } else {
            while(!Heap.empty() && !Erased.empty() && Heap.top() == Erased.top()) {
                Heap.pop();
                Erased.pop();
            }
            
            cout << -Heap.top() << '\n';
        }
    }
    
    return 0;
}