Cod sursa(job #2399050)

Utilizator ezioconnorVlad - Gabriel Iftimescu ezioconnor Data 6 aprilie 2019 19:44:37
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <bits/stdc++.h>

using namespace std;

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

priority_queue <int, vector <int>, greater <int>> q;
int f[200001], k, v[200001];

int main()
{
    int n, c, x;
    in >> n;
    for (int i = 1; i <= n; ++i)
    {
        in >> c;
        if (c == 1)
        {
            in >> x;
            q.push(x);
            f[++k] = x;
        }
        else if (c == 2)
        {
            in >> x;
            int nr = 0;
            while (q.top() != f[x] && !q.empty())
            {
                v[++nr] = q.top();
                q.pop();
            }
            q.pop();
            for (int j = 1; j <= nr; ++j)
                q.push(v[j]);
        }
        else
            out << q.top() << '\n';
    }
    return 0;
}