Cod sursa(job #1147587)

Utilizator span7aRazvan span7a Data 19 martie 2014 23:00:06
Problema Heapuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
FILE *f=fopen("heapuri.in","r");
FILE *g=fopen("heapuri.out","w");
struct val
{
    int x;
    int poz;
};
struct cmp
{
    bool operator() (val a,val b)
    {
        return a.x>b.x;
    }
};
priority_queue< val,vector<val>,cmp > heap;
vector<val> aux;
int n;
int main()
{
    int i,cer,xx,nr=0;
    fscanf(f,"%d",&n);
    for(i=1;i<=n;i++)
    {
        fscanf(f,"%d",&cer);
        if(cer==1)
        {
            fscanf(f,"%d",&xx);
            nr++;
            val auxx;
            auxx.x=xx;
            auxx.poz=nr;
            heap.push(auxx);
        }
        else
            if(cer==2)
            {
                fscanf(f,"%d",&xx);
                while(heap.top().poz!=xx){aux.push_back(heap.top());heap.pop();}
                if(heap.size()) heap.pop();
                while(aux.size())
                {
                    heap.push(aux.back());
                    aux.pop_back();
                }

            }
            else fprintf(g,"%d\n",heap.top().x);

    }

}