Pagini recente » Cod sursa (job #3160353) | Cod sursa (job #3151687) | Cod sursa (job #777435) | Cod sursa (job #2001477) | Cod sursa (job #2616045)
#include <bits/stdc++.h>
#define nmax 200005
using namespace std;
ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");
int n, heap[nmax], val[nmax], poz[nmax], i;
inline void Swap (int x, int y) {
swap (heap[x], heap[y]);
swap (poz[heap[x]], poz[heap[y]]);
}
inline bool fcmp (int x,int y) {
return x < y;
}
inline void UpHeap (int x) {
int tata = x / 2;
if (tata && fcmp (val[heap[x]],val[heap[tata]])) {
Swap (x, tata);
UpHeap (tata);
}
}
inline void DownHeap (int x) {
int son = x * 2;
if (son + 1 <= n && fcmp (val[heap[son + 1]], val[heap[son]])) son ++;
if (son <= n && fcmp(val[heap[son]], val[heap[x]])) {
Swap (son, x);
DownHeap (son);
}
}
inline void Insert (int x) {
i ++;
val[i] = x;
n ++;
heap[n] = i;
poz[i] = n;
UpHeap (n);
}
inline void Erase (int x) {
Swap (x, n);
n --;
DownHeap (x);
}
inline void Read_Solve () {
int Q, op, x;
fin >> Q;
while (Q --) {
fin >> op;
if (op == 1) {
fin >> x;
Insert (x);
}
if (op == 2) {
fin >> x;
Erase (poz[x]);
}
if (op == 3) fout << val[heap[1]] << '\n';
}
}
inline void Close () {
fin.close ();
fout.close ();
}
int main() {
Read_Solve ();
Close ();
return 0;
}