Pagini recente » Cod sursa (job #2686034) | Cod sursa (job #2135171) | Cod sursa (job #2337525) | Cod sursa (job #1671728) | Cod sursa (job #2270133)
#include <fstream>
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
int v[200005],heap[200005],v1[200005],of[200005];
void heapup(int x)
{
if (x>1)
{
if (v1[heap[x]]<v1[heap[x/2]])
{
swap(heap[x],heap[x/2]);
heapup(x/2);
}
}
}
void heapdown(int x,int u)
{
int st,dr;
if (x*2<=u)
{
st=v1[heap[x*2]];
if (2*x+1<=u)
{
dr=v1[heap[x*2+1]];
}
else
{
dr=st+1;
}
if (min(st,dr)<v1[heap[x]])
{
if (st<dr)
{
swap(heap[x],heap[2*x]);
heapdown(2*x,u);
}
else
{
swap(heap[x],heap[2*x+1]);
heapdown(2*x+1,u);
}
}
}
}
int n,q,i,x,nr,poz,j,numar,nr2=0;
int main()
{
f>>n;
q=0;
numar=0;
for (i=1;i<=n;i++)
{
f>>x;
if (x==1)
{
f>>nr;
q++;
numar++;
v1[numar]=nr;
heap[q]=numar;
heapup(q);
}
else
if (x==2)
{
f>>poz;
v1[poz]=1000000001;
if (v1[heap[1]]==1000000001)
{
swap(heap[1],heap[q]);
q--;
heapdown(1,q);
}
}
else
{
g<<v1[heap[1]]<<'\n';
}
}
return 0;
}