Cod sursa(job #1977887)

Utilizator FrequeAlex Iordachescu Freque Data 6 mai 2017 13:33:58
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.97 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <vector>

using namespace std;

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

priority_queue <int, vector<int>, greater<int>> p, q;
vector <int> history;

int n, cod, x;

int main()
{
    fin >> n;
    while (n--)
    {
        fin >> cod;
        switch (cod)
        {
        case 1:
            {
                fin >> x;
                p.push(x);
                history.push_back(x);
                break;
            }
        case 2:
            {
                fin >> x;
                q.push(history[x - 1]);
                break;
            }
        case 3:
            {
                while (!p.empty() && !q.empty() && p.top() == q.top())
                {
                    p.pop();
                    q.pop();
                }
                fout << p.top() << '\n';
                break;
            }
        }
    }
    return 0;
}