Pagini recente » Cod sursa (job #1689435) | Cod sursa (job #783309) | Cod sursa (job #2969576) | Cod sursa (job #1146079) | Cod sursa (job #1467497)
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <time.h>
#include <bitset>
#include <string>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <limits.h>
#include <algorithm>
#include <deque>
#define nmax 200010
#define mod 1999999973
using namespace std;
int n,i,heap[nmax],tip,nr,t[nmax],pos[nmax],x,nrx;
void Swap(int &a,int &b)
{
swap(a,b); swap(pos[a],pos[b]);
}
void heapup(int v)
{
int k=heap[v];
while (v>1 && t[heap[v]]<t[heap[v/2]]) {
Swap(heap[v],heap[v/2]);
v=v/2;
}
heap[v]=k;
}
void heapdown(int v)
{
int w=v*2;
while (w<=nrx) {
if (w+1<=nrx && t[heap[w]]>t[heap[w+1]]) w++;
if (t[heap[v]]>t[heap[w]]) Swap(heap[v],heap[w]); else break;
v=w; w=w*2;
}
}
void add_heap(int x)
{
nrx++; nr++; heap[nrx]=nr; t[nr]=x; pos[nr]=nr;
heapup(nr);
}
void delete_heap(int x)
{
Swap(heap[x],heap[nrx]); nrx--;
heapdown(x);
}
int main() {
freopen("heapuri.in","r",stdin);
freopen("heapuri.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;i++) {
scanf("%d",&tip);
switch (tip) {
case 1:{ scanf("%d",&x); add_heap(x); break; }
case 2:{ scanf("%d",&x); delete_heap(pos[x]); break; }
case 3:{ printf("%d\n",t[heap[1]]); break; }
}
}
return 0;
}