Pagini recente » Cod sursa (job #528730) | Cod sursa (job #271359) | Cod sursa (job #2875939) | Cod sursa (job #3241953) | Cod sursa (job #1787377)
#include <cstdio>
#include <iostream>
#define lenght_max 200005
int n,l,m;
int heap[lenght_max],poz[lenght_max];
using namespace std;
void inserare(int x)
{
while((x/2!=0)&&(heap[x]<heap[x/2]))
{
swap(heap[x],heap[x/2]);
poz[heap[x]]=x;
poz[heap[x/2]]=x/2;
x=x/2;
}
}
int main()
{
FILE *f=fopen("heapuri.in","r");
FILE *g=fopen("heapuri.out","w");
int i,cod,x;
fscanf(f,"%d",&n);
for(i=1;i<=n;i++)
{
fscanf(f,"%d",&cod);
if(cod<3)
fscanf(f,"%d",&x);
if(cod==1)
{
l++;
m++;
heap[l]=x;
poz[m]=l;
inserare(x);
}
if(cod==3)
fscanf(f,"%d\n",heap[1]);
}
return 0;
}