Pagini recente » Cod sursa (job #378961) | Cod sursa (job #581178) | Cod sursa (job #2551460) | Cod sursa (job #404704) | Cod sursa (job #1538293)
#include <iostream>
#include <fstream>
#define nmax 200001
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
int n,v[nmax],cron[nmax],k;
void exch(int a,int b)
{
int aux;
aux=v[a];
v[a]=v[b];
v[b]=aux;
}
void down(int poz)
{
while(poz*2 <= k)
{
if(poz*2+1 > k)
{
if(v[poz]>v[poz*2])exch(poz,poz*2),poz=poz*2;
}
else
{
if(v[poz*2] < v[poz*2+1])
{
if(v[poz]>v[poz*2])exch(poz,poz*2),poz=poz*2;
}
else if(v[poz]>v[poz*2+1])exch(poz,poz*2+1),poz=poz*2+1;
}
}
}
void add()
{
int x; f>>x;
k++;
v[k]=x;
cron[k]=x;
int z=k;
while(z/2)
{
if(v[z] < v[z/2])
exch(z,z/2);
z=z/2;
}
}
void substr()
{
int x;
f>>x;
x=cron[x];
for(int i=1;i<=k;i++)
{
if(x==v[i])
{
x=i;
break;
}
}
exch(x,k);
k--;
down(x);
}
void min()
{
g<<v[1]<<endl;
}
void read()
{
int a,b;
f>>n;
for(int i=1;i<=n;i++)
{
f>>a;
if(a==1)add();
else if(a==2)substr();
else min();
//cout<<"sir: ";
//for(int i=1;i<=k;i++)cout<<v[i]<<" ";cout<<endl;
}
}
int main()
{
read();
return 0;
}