Pagini recente » Cod sursa (job #2047088) | Cod sursa (job #364160) | Cod sursa (job #1631888) | Cod sursa (job #997462) | Cod sursa (job #850694)
Cod sursa(job #850694)
#include<cstdio>
#include<cstdlib>
#define inf 20000000
#define MAXN 200001
int v[MAXN],poz[MAXN],h[MAXN];
int u,nr,max;
void swap(int &a, int &b)
{
int aux=a;
a=b;
b=aux;
}
void upheap(int nod)
{
if(nod>1)
if(v[h[nod/2]]>v[h[nod]])
{
swap(h[nod/2],h[nod]);
poz[h[nod]]=nod;
poz[h[nod/2]]=nod/2;
upheap(nod/2);
}
}
void downheap(int nod)
{
int f;
if(nod*2<=u)
{
f=nod*2;
if(nod*2+1<=u && v[h[f]]>v[h[nod*2+1]])
f=f+1;
if(v[h[f]]<v[h[nod]])
{
swap(h[f],h[nod]);
poz[h[f]]=f;
poz[h[nod]]=nod;
downheap(f);
}
}
}
void inserare(int x)
{
v[++u]=x;
h[u]=u;
poz[u]=u;
upheap(u);
}
void stergere(int x)
{
v[x]=inf;
downheap(poz[x]);
}
int main()
{
freopen("heapuri.in","r",stdin);
freopen("heapuri.out","w",stdout);
int x,n,op,i;
scanf("%d",&n);
for (i=1;i<=n;++i)
{
scanf("%d",&op);
if(op==1)
{
scanf("%d",&x);
inserare(x);
}
if(op==2)
{
scanf("%d",&x);
stergere(x);
}
if (op==3)
printf("%d\n",v[h[1]]);
}
return 0;
}