Pagini recente » Cod sursa (job #1391703) | Cod sursa (job #1589244) | Cod sursa (job #1746354) | Cod sursa (job #1951910) | Cod sursa (job #1391805)
#include <stdio.h>
int cron[200001];
int n,m,lun;
int heap[200001],tip,nr;
void vertop(int p)
{
if(heap[p]<heap[2*p]&&heap[p]<heap[2*p+1]) return;
if(heap[p]>heap[2*p]&&heap[2*p]<heap[2*p+1])
{
int temp=heap[p];
heap[p]=heap[2*p];
heap[2*p]=temp;
}
else if(heap[p]>heap[2*p+1]&&heap[2*p+1]<heap[2*p])
{
int temp=heap[p];
heap[p]=heap[2*p+1];
heap[2*p+1]=temp;
}
}
void ver(int p)
{
int temp;
if(p==1) vertop(p);
else
{
if(heap[p]<heap[p/2])
{
temp=heap[p];
heap[p]=heap[p/2];
heap[p/2]=temp;
ver(p/2);
}
}
}
void el(int p)
{
int temp;
temp=heap[m];
heap[m]=heap[p];
heap[p]=temp;
heap[m]=1000000001;
m--;
if(p!=1) ver(p);
else vertop(p);
}
int main()
{
freopen ("heapuri.in","r",stdin);
freopen ("heapuri.out","w",stdout);
for(int i=1;i<=200000;i++) heap[i]=1000000001;
scanf("%d",&n);
for(int x=1;x<=n;x++)
{
scanf("%d",&tip);
if(tip==1)
{
scanf("%d",&nr);
m++;
lun++;
cron[lun]=nr;
heap[m]=nr;
ver(m);
//for(int i=1;i<=m;i++) printf("%d ",heap[i]);
// printf("\n");
}
else if(tip==2)
{
scanf("%d",&nr);
for(int i=1;i<=m;i++)
{
if(heap[i]==cron[nr])
{
el(i);
break;
}
}
//for(int i=1;i<=m;i++) printf("%d ",heap[i]);
// printf("\n");
}
else printf("%d\n",heap[1]);
}
}