Cod sursa(job #781079)

Utilizator stefanzzzStefan Popa stefanzzz Data 23 august 2012 10:05:23
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <algorithm>
#define MAXN 200005
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");

long n,tip,x,v[MAXN],h[MAXN];
bool sters[MAXN];

bool comp(long a,long b){
    return v[a]>v[b];}

int main()
{
    long i;
    f>>n;
    f>>tip>>x;
    v[++v[0]]=x;
    h[++h[0]]=1;
    make_heap(h+1,h+2,comp);
    for(i=2;i<=n;i++){
        f>>tip;
        switch(tip){
            case 1:
                f>>x;
                v[++v[0]]=x;
                h[++h[0]]=v[0];
                push_heap(h+1,h+h[0]+1,comp);
                break;
            case 2:
                f>>x;
                sters[x]=1;
                break;
            case 3:
                x=h[1];
                while(sters[x]){
                    pop_heap(h+1,h+h[0]+1,comp);
                    h[0]--;
                    x=h[1];}
                g<<v[x]<<'\n';}}
    f.close();
    g.close();
    return 0;
}