Cod sursa(job #1368495)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 2 martie 2015 18:04:43
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

#define pp pair<int,int>

priority_queue<pp, vector<pp>, greater<pp> > MinHeap;
unordered_set<int> Hash;

int main()
{
    ifstream in("heapuri.in");
    ofstream out("heapuri.out");

    int N, time = 0;
    in >> N;

    while ( N-- )
    {
        int tip, x;

        in >> tip;

        if ( tip == 1 )
        {
            in >> x;
            MinHeap.push( {x, ++time} );
        }

        if ( tip == 2 )
        {
            in >> x;
            Hash.insert(x);
        }

        if ( tip == 3 )
        {
            while ( MinHeap.size() && Hash.find(MinHeap.top().second) != Hash.end() )
                MinHeap.pop();

            out << MinHeap.top().first << "\n";
        }
    }

    return 0;
}