Pagini recente » Cod sursa (job #2233530) | Cod sursa (job #2654576) | Cod sursa (job #1437757) | Cod sursa (job #2638554) | Cod sursa (job #2775162)
#include <fstream>
using namespace std;
ifstream in("heapuri.in");
ofstream out("heapuri.out");
int n,cod,pmax,nr,x;
struct arbore{int val,nr;}a[200010];
bool v[200010];
int main()
{
in>>n;
for(int i=1;i<=n;++i)
{
in>>cod;
if(cod==3)
out<<a[1].val<<'\n';
else if(cod==1)
{
in>>x;
++pmax;
a[++nr].nr=nr;
a[nr].val=x;
int poz=nr;
while(poz>1&&a[poz].val<a[poz/2].val)
{
swap(a[poz],a[poz/2]);
poz/=2;
}
}
else
{
in>>x;
v[x]=true;
while(v[a[1].nr]==true)
{
swap(a[1],a[pmax]);
--pmax;
int poz=1;
while(poz*2<pmax&&(a[poz].val>a[poz*2].val||a[poz].val>a[poz*2+1].val))
{
if(a[poz*2].val<a[poz*2+1].val)
{
swap(a[poz*2],a[poz]);
poz*=2;
}
else
{
swap(a[poz*2+1],a[poz]);
poz*=2;
++poz;
}
}
if(poz*2==pmax&&a[poz*2].val<a[poz].val)
swap(a[poz*2],a[poz]);
}
}
}
return 0;
}