Pagini recente » Cod sursa (job #687385) | Cod sursa (job #848267) | Cod sursa (job #2124290) | Cod sursa (job #949454) | Cod sursa (job #2327378)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("heapuri.in");
ofstream g ("heapuri.out");
const int nmax=2e5+3;
int n,t,nr,v[nmax],usu[nmax],poz[nmax],x,cod;
void push(int x)
{
while(x/2&&v[usu[x]]<v[usu[x/2]])
{
swap(usu[x],usu[x/2]);
poz[usu[x]]=x;
poz[usu[x/2]]=x/2;
x/=2;
}
}
void pop(int x)
{
int y=0;
while(x!=y)
{
y=x;
if(y*2<=t&&v[usu[x]]>v[usu[y*2]]) x=y*2;
if(y*2+1<=t&&v[usu[x]]>v[usu[y*2+1]]) x=y*2+1;
swap(usu[x],usu[y]);
poz[usu[x]]=x;
poz[usu[y]]=y;
}
}
int main()
{
ios::sync_with_stdio(false);
f>>n;
for(int i=1;i<=n;++i)
{
f>>cod;
if(cod<3) f>>x;
if(cod==1)
{
++t;
++nr;
v[nr]=x;
usu[t]=nr;
poz[nr]=t;
push(t);
}
if(cod==2)
{
v[x]=-1;
push(poz[x]);
poz[usu[1]]=0;
usu[1]=usu[t--];
poz[usu[1]]=1;
if(t>1) pop(1);
}
if(cod==3) g<<v[usu[1]]<<'\n';
}
return 0;
}