Cod sursa(job #2100876)

Utilizator AsttridMocanu Ada Astrid Asttrid Data 6 ianuarie 2018 15:15:57
Problema Heapuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include<bits/stdc++.h>
using namespace std;
ifstream in("heapuri.in");
ofstream out("heapuri.out");


struct elem {int x,poz;
bool operator < (const elem &a)const{return x>a.x;}
};

int n,p;

int main(){
    priority_queue <elem> Q,Q1;
in>>n;
int i,k,x;
k=0;
elem w;
for(i=1;i<=n;i++)
    {in>>p;
    if(p==1)
    {   in>>x;
        w.x=x;
        k++;
        w.poz=k;
        Q.push(w);}



    else if (p==2){in>>x;
    w=Q.top();Q.pop();
    while(w.poz!=x){
    Q1.push(w);
    w=Q.top();Q.pop();}

    while(!Q1.empty()){w=Q1.top();Q1.pop();Q.push(w);}}


    else if(p==3){w=Q.top();
    out<<w.x<<"\n";}

}


return 0;}