Pagini recente » Cod sursa (job #2343094) | Cod sursa (job #2124594) | Cod sursa (job #3134381) | Cod sursa (job #1500294) | Cod sursa (job #1022408)
#include<stdio.h>
int v[200010],poz[200010],h[200010],n,nr;
inline void swap(int &a,int &b)
{
int aux;
aux=a;a=b;b=aux;
}
inline void adaug(int x)
{
int p;
p=n;
while(p/2 && v[h[p]]<v[h[p/2]])
{
swap(h[p],h[p/2]);
poz[h[p]]=p;
poz[h[p/2]]=p/2;
p=p/2;
}
}
inline void push()
{
int x;
scanf("%d",&x);
++n;++nr;
v[nr]=x;
h[n]=nr;
poz[nr]=n;
}
inline void scoate(int x)
{
int p=0;
while(x!=p)
{
if(p*2<=n && v[h[x]]>v[h[2*p]])
x=2*p;
if(p*2+1<=n && v[h[x]]>v[h[2*p+1]])
x=2*p+1;
swap(h[x],h[p]);
poz[h[x]]=x;
poz[h[p]]=p;
}
}
inline void pop()
{
int x;
scanf("%d",&x);
v[x]=-1;
adaug(poz[x]);
poz[h[1]]=0; /////////////
h[1]=h[n];
--n;
poz[h[1]]=1;
if(n>1)
scoate(1);
}
int main()
{
freopen("heapuri.in","r",stdin);
freopen("heapuri.out","w",stdout);
int m,op;
scanf("%d",&m);
while(m--)
{
scanf("%d",&op);
switch(op)
{
case 1:{push();break;}
case 2:{pop();break;}
case 3:{printf("%d\n",v[h[1]]);break;}
}
}
return 0;
}