Cod sursa(job #2734828)

Utilizator StarkillerCalin Stafie Starkiller Data 1 aprilie 2021 14:25:43
Problema Heapuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.26 kb
#include <bits/stdc++.h>

using namespace std;

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

priority_queue <pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> heap;
int n, op, x, index_push = 1;
int main()
{
    fin >> n;
    for (int t = 1 ; t <= n; ++t)
    {
        fin >> op;
        switch(op)
        {
        case 1:
            {
                fin >> x;
                heap.push({x, index_push});
                ++index_push;
                break;
            }
        case 2:
            {
                fin >> x;
                priority_queue <pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> dummy;
                while (!heap.empty() && heap.top().second != x)
                {
                    dummy.push(heap.top());
                    heap.pop();
                }

                heap.pop();

                while (!heap.empty())
                {
                    dummy.push(heap.top());
                    heap.pop();
                }
                heap = dummy;

                break;
            }
        case 3:
            {
                gout << heap.top().first << '\n';
                break;
            }
        }
    }
    return 0;
}