Pagini recente » Cod sursa (job #1201605) | Cod sursa (job #946762) | Cod sursa (job #1086199) | Cod sursa (job #2888227) | Cod sursa (job #1041358)
#include<cstdio>
#include<cstring>
#include<vector>
#define pb push_back
#define N_MAX 200010
using namespace std;
int H[N_MAX],poz[N_MAX],V[N_MAX];
int i,N,k,x,l,NR;
inline void swap(int x,int y)
{
int aux=H[x];
H[x]=H[y];
H[y]=aux;
poz[H[x]]=x;
poz[H[y]]=y;
}
inline void Heap_Up(int x)
{
int t=x/2;
if (V[H[x]]<V[H[t]])
{
swap(x,t);
Heap_Up(t);
}
}
inline void Heap_Down(int x)
{
int St=x*2,p,Dr=x*2+1;
if (St<=NR)
{
p=St;
if(Dr<NR)
{
if (V[H[St]]>V[H[Dr]]) p=Dr;
}
if (V[H[p]]<V[H[x]])
{
swap(x,p);
Heap_Down(p);
}
}
}
int main()
{
freopen("heapuri.in","r",stdin);
freopen("heapuri.out","w",stdout);
scanf("%d\n",&N);
l=0;
for(i=1;i<=N;i++)
{
scanf("%d",&k);
if (k==1)
{
scanf("%d",&x);
//INSERAREA ELEMENTULUI
V[++l]=x;
poz[l]=l;
H[++NR]=l;
Heap_Up(l);
}
if (k==2)
{
scanf("%d",&x);
//STERGEREA ELEMENTULUI
int p=poz[x];
int aux=H[p];
H[p]=H[NR];
H[NR]=aux;
poz[H[p]]=p;
poz[H[NR]]=NR;
NR--;
Heap_Down(p);
}
if (k==3)
{
//AFISAREA REZULTATULUI
printf("%d\n",V[H[1]]);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}