Pagini recente » Cod sursa (job #1878814) | Cod sursa (job #2297095) | Cod sursa (job #225513) | Cod sursa (job #2105949) | Cod sursa (job #563492)
Cod sursa(job #563492)
#include <stdio.h>
#define DIM 200005
int N, X, H[DIM], I[DIM];
void swap (int &a, int &b)
{
int x = a;
a = b;
b = x;
}
void urca (int n)
{
int t = n >> 1;
if (t && H[t] > H[n])
{
swap (H[t], H[n]);
swap (I[t], I[n]);
urca (t);
}
}
int main ()
{
freopen ("heapuri.in", "r", stdin);
freopen ("heapuri.out", "w", stdout);
scanf ("%d", &N);
for (int i = 0, t, x; i < N; i++)
{
scanf ("%d", &t);
switch (t)
{
case 1:
scanf ("%d", &X);
H[++H[0]] = X;
I[++I[0]] = H[0];
urca (H[0]);
break;
case 2:
scanf ("%d", &X);
x = I[X];
urca (x);
break;
case 3:
printf ("%d ", H[1]);
break;
}
}
return 0;
}