Pagini recente » Cod sursa (job #1856660) | Cod sursa (job #2977642) | Cod sursa (job #3221486) | Cod sursa (job #2615610) | Cod sursa (job #1869909)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int n, m;
int a[200005], ran[200005];
unordered_map <int,int> poz;
inline void Push(int x)
{
int k, tata;
a[++n] = x;
poz[x] = n;
k = n;
while(k > 1)
{
tata = k / 2;
if(a[k] >= a[tata])
return;
swap(a[k], a[tata]);
swap(poz[a[k]], poz[a[tata]]);
k = tata;
}
}
inline void Pop(int k)
{
int fiu;
a[k] = a[n];
poz[a[n]] = k;
n--;
while(2 * k <= n)
{
fiu = 2 * k;
if(fiu + 1 <= n && a[fiu] > a[fiu + 1])
fiu++;
if(a[k] <= a[fiu])
return;
swap(a[k], a[fiu]);
swap(poz[a[k]], poz[a[fiu]]);
k = fiu;
}
}
inline void Read()
{
int i, op, x, k;
k = 0;
fin >> m;
for(i = 1; i <= m; i++)
{
fin >> op;
if(op == 1)
{
fin >> x;
k++;
ran[k] = x;
Push(x);
}
else if(op == 2)
{
fin >> x;
x = ran[x];
x = poz[x];
Pop(x);
}
else fout << a[1] << "\n";
}
}
int main()
{
Read();
return 0;
}