Pagini recente » Cod sursa (job #2491885) | Cod sursa (job #1225851) | Cod sursa (job #2136750) | Cod sursa (job #221481) | Cod sursa (job #1162885)
#include <iostream>
#include <cstdio>
#define t (poz >> 1)
#define f1 (y << 1)
#define f2 (f1 + 1)
#define nmax 200005
using namespace std;
int H[nmax], P[nmax], V[nmax];
int top, lg;
int n;
void push(int poz)
{
while(t && V[H[poz]] < V[H[t]])
{
swap(H[poz], H[t]);
P[H[poz]] = poz;
P[H[t]] = t;
poz = t;
}
}
void pop(int poz)
{
int y;
while(poz != y)
{
y = poz;
if(f1 <= lg && V[H[poz]] > V[H[f1]])
poz = f1;
if(f2 <= lg && V[H[poz]] > V[H[f2]])
poz = f2;
swap(H[poz], H[y]);
P[H[poz]] = poz;
P[H[y]] = y;
}
}
int main()
{
freopen("heapuri.in","r",stdin);
freopen("heapuri.out","w",stdout);
scanf("%d",&n);
while(n--)
{
int tip, x;
scanf("%d",&tip);
if(tip == 1)
{
scanf("%d",&x);
++top; ++lg;
P[top] = lg;
V[top] = x;
H[lg] = top;
push(lg);
}
else if(tip == 2)
{
scanf("%d",&x);
V[x] = -1;
push(P[x]);
P[H[1]] = 0;
H[1] = H[lg--];
P[H[1]] = 1;
if(lg > 1)
pop(1);
}
else
printf("%d\n",V[H[1]]);
}
return 0;
}