Pagini recente » Cod sursa (job #625543) | Cod sursa (job #2089989) | Cod sursa (job #1777562) | Rating Dohotariu Adrian (Podie) | Cod sursa (job #1773806)
#include <cstdio>
#include <algorithm>
#define N 200005
using namespace std;
int h[N],poz[N],a[N],l,n,nr;
void push(int x)
{
while (x/2 && a[h[x]]<a[h[x/2]])
{
swap(h[x],h[x/2]);
poz[h[x]]=x;
poz[h[x/2]]=x/2;
x/=2;
}
}
void cut(int x)
{
int y=0;
while (x!=y)
{
y=x;
if (y*2<=l && a[h[x]]>a[h[y*2]]) x=y*2;
if (y*2+1<=l && a[h[x]]>a[h[y*2+1]]) x=y*2+1;
swap(h[x],h[y]);
poz[h[x]]=x;
poz[h[y]]=y;
}
}
int main()
{
int i,c,x;
freopen("heapuri.in","r",stdin);
freopen("heapuri.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;i++)
{
scanf("%d",&c);
if (c==1) {
scanf("%d",&x);
l++;nr++;
a[nr]=x;
h[l]=nr;
poz[nr]=l;
push(l);
}
if (c==2) {
scanf("%d",&x);
a[x]=-1;
push(poz[x]);
poz[h[1]]=0;
h[1]=h[l--];
poz[h[1]]=1;
if (l>1) cut(1);
}
if (c==3) printf("%d\n",a[h[1]]);
}
}