Pagini recente » Cod sursa (job #3164117) | Cod sursa (job #2964296) | Cod sursa (job #3170924) | Cod sursa (job #482939) | Cod sursa (job #2466178)
#include <fstream>
using namespace std;
ifstream in("heapuri.in");
ofstream out("heapuri.out");
int n,poz[200001],k,i,ha,g;
struct nya{int st,dr;};
nya h[200001];
void swapp(int x)
{
swap (h[x],h[x/2]);
poz[h[x/2].dr]=x/2;
poz[h[x].dr]=x;
}
void heapup (int x)
{
if (x>1) {
if (h[x].st<h[x/2].st)
{
swapp (x);
heapup(x/2);
}
}
}
void heapdown(int x)
{
int ma=h[x].st;
if (x*2<=k)
{
if (h[x*2].st<h[x].st) ma=h[x*2].st;
if (x*2<k)
{
if (h[x*2+1].st<h[x].st) ma=h[x*2].st;
}
}
if (ma!=h[x].st)
{
if (ma==h[x*2].st) {swapp(x*2); heapdown(x*2);}
else if (ma==h[x*2+1].st) {swapp(x*2+1); heapdown(x*2+1);}
}
}
int main()
{
in>>n;
for (i=1;i<=n;++i)
{
in>>ha;
if (ha==1) {in>>g; k++; poz[k]=k; h[k].st=g; h[k].dr=k; heapup(k);}
else if (ha==3) {out<<h[1].st<<'\n';}
else {in>>g; h[poz[g]].st=1000000001; heapdown(poz[g]);}
}
return 0;
}