Cod sursa(job #1420918)

Utilizator code_and_rosesUPB Dinu Neatu Rotaru code_and_roses Data 19 aprilie 2015 09:54:00
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
// Heapuri - O(logN)
#include <fstream>
#include <queue>
#include <bitset>
#define Nmax 200099
#define mp make_pair
#define x first
#define y second
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
typedef pair<int,int> PP;

int N,K;

priority_queue< PP , vector< PP >, greater < PP > > pq;

bitset < Nmax > bad;

int main()
{
    f>>N;
    for (int i=1; i<=N; ++i)
    {
        int op,val,poz;
        f>>op;
        if (op==1) f>>val , pq.push(PP(val,++K));
        if (op==2) f>>poz , bad[poz]=1;
        if (op==3)
        {
             while(bad[pq.top().y]) pq.pop();
             g<<pq.top().x<<'\n';
        }
    }
    f.close();g.close();
    return 0;
}