Cod sursa(job #1986901)

Utilizator ArctopusKacso Peter-Gabor Arctopus Data 29 mai 2017 11:16:44
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <queue>
#include <fstream>

using namespace std;

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

const int NLIM = 2e5 + 10;
int N;
int bv[NLIM];

struct xS
{
    int val, time;
};

class comparC
{
public:
    bool operator() ( xS x1, xS x2 )
    {
        return x1.val > x2.val;
    }
};

int main()
{
    priority_queue< xS, vector< xS >, comparC > hip;

    fin >> N;
    int i = 1;
    while( N-- )
    {
        int t;
        fin >> t;

        if( t == 1 )
        {
            xS x;
            x.time = i; ++i;
            fin >> x.val;
            hip.push( x );
        }
        else if( t == 2 )
        {
            int x;
            fin >> x;
            bv[x] = 1;
        }
        else
        {
            while( bv[hip.top().time] )
            {
                //cout << "   " << hip.top().val << "\n";
                hip.pop();
            }
           // cout << hip.top().time << " ";
            fout << hip.top().val << "\n";
        }
    }

    return 0;
}