Cod sursa(job #1368479)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 2 martie 2015 17:56:15
Problema Heapuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <bits/stdc++.h>

using namespace std;

struct Node
{
    int val;
    int timp;

    bool operator < (const Node& N) const
    {
        return val > N.val;
    }
};

priority_queue<Node> MinHeap;
unordered_set<int> Hash;

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

    int N;
    in >> N;

    while ( N-- )
    {
        int tip, x, time = 0;

        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().timp) != Hash.end() )
                MinHeap.pop();

            if ( MinHeap.size() )
                cout << MinHeap.top().val << "\n";
            else
                cerr << "Error";
        }
    }

    return 0;
}