Pagini recente » Cod sursa (job #1536809) | Cod sursa (job #716863) | Cod sursa (job #93665) | Cod sursa (job #344175) | Cod sursa (job #452401)
Cod sursa(job #452401)
#include<stdlib.h>
#include<cstdio>
#include<algorithm>
using namespace std;
int h[200005],n,poz,ind[200005],a[200005];
int max()
{
return h[1];
}
void swap(int &x, int &y)
{int aux;
aux = x;
x = y;
y = aux;
}
void sift( int k)
{int son;
do
{
son = 0;
if ((k<<1) <= n)
{
son = (k<<1);
if ((k<<1) <= n && h[k<<1] > h[(k<<1) + 1])
son = (k<<1) + 1;
}
if ((h[son]) >= h[k]) son = 0;
if (son)
{
swap(h[k],h[son]);
k = son;
}
}while (son);
}
void perc( int k)
{int key;
key = h[k];
while (k > 1 && key < h[k>>1])
{
h[k] = h[k>>1];
k = (k>>1);
}
h[k] = key;
}
void buildheap()
{
for (int i = n / 2; i > 0; i--)
sift(i);
}
void elimin( int k)
{
h[k] = h[n];
--n;
if (k > 1 && h[k] < h[k>>1]) perc(k);
else sift(k);
}
void ins( int k)
{
h[++n] = k;
perc(n);
}
int main()
{int ct;
int x,y,i,m;
freopen("heapuri.in","r",stdin);
freopen("heapuri.out","w",stdout);
ct = 1;
scanf("%d",&m);
for (i = 1; i <= m; i++)
{
x = 0;
scanf("%d",&x);
if (x == 1) { scanf("%d",&y);
a[ct] = y;
ct++;
ins(y);
}
if (x == 2) { scanf("%d",&y);
for (i = 1; i <= n; i++)
if (h[i] == a[y]) {poz = i;break;}
elimin(poz);
}
if (x == 3) {printf("%d ",max());
printf("\n");}
}
return 0;
}