Pagini recente » Cod sursa (job #2316554) | Cod sursa (job #1763635) | Clasament Urmasii lui Moisil 2016 Clasele 11-12 | Cod sursa (job #2331799) | Cod sursa (job #2100876)
#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;}