Pagini recente » Cod sursa (job #405562) | Cod sursa (job #2771298) | Cod sursa (job #2692287) | Cod sursa (job #2316278) | Cod sursa (job #3174945)
#include <bits/stdc++.h>
#define NMAX 200005
using namespace std;
ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");
int n;
pair<int,int> H[NMAX];
int poz[NMAX];
int nr;
void Insert(int value,int pos) {
if (pos==1) {
H[pos]={value,nr};
poz[nr]=pos;
return;
}
if (!(value>=H[pos/2].first)) H[pos]=H[pos/2], poz[H[pos/2].second]=pos, Insert(value,pos/2);
else H[pos]={value,nr}, poz[nr]=pos;
}
void Combine(int pos) {
int x=H[pos].first,time=H[pos].second, tata=pos, fiu=2*tata;
while (fiu<=n) {
if (fiu+1<=n && H[fiu+1].first<H[fiu].first) fiu++;
if (H[fiu].first<x) {
H[tata]=H[fiu]; poz[H[fiu].second]=tata;
tata=fiu;
fiu=2*tata;
}
else break;
}
H[tata]={x,time}; poz[time]=tata;
}
void Print() {
for (int i=1; i<=n; i++) fout<<H[i].first<<' ';
fout<<'\n';
}
int main()
{
int t;
fin>>t;
while (t--) {
int tip,x;
fin>>tip;
if (tip!=3) fin>>x;
switch (tip) {
case 1:
nr++;
Insert(x,++n);
break;
case 2:
H[poz[x]]=H[n--];
Combine(poz[x]);
break;
case 3:
fout<<H[1].first<<'\n';
break;
}
}
return 0;
}