Cod sursa(job #1602884)

Utilizator RadduFMI Dinu Radu Raddu Data 16 februarie 2016 23:09:14
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");

struct elem
{ int x,ord; } el;

struct cmp
{
  bool operator() (elem a,elem b)
  { return a.x>b.x; }
};

priority_queue <elem,vector<elem>,cmp> heap;
int n,del[200005];
int main()
{ int i,t,k=0,val;
    f>>n;
    for(i=1;i<=n;i++)
    { f>>t;
      if (t==1) {f>>val; el.x=val; k++; el.ord=k; heap.push(el);}
      if (t==2) {f>>val; del[val]=1;}
      if (t==3) { while(del[heap.top().ord]) heap.pop(); g<<heap.top().x<<"\n"; }
    }
    return 0;
}