Pagini recente » Cod sursa (job #2488691) | Cod sursa (job #471857) | Cod sursa (job #2039084) | Cod sursa (job #1839798) | Cod sursa (job #1224099)
#include<fstream>
using namespace std;
int T, op, a[200007], h[200007], c, p, poz[200007], x, dh, aux, n;
ifstream in("heapuri.in");
ofstream out("heapuri.out");
int main(){
in>>T;
for(;T--;){
in>>op;
if(op==3){
out<<a[h[1]]<<"\n";
continue;
}
if(op==1){
in>>x;
a[++n]=x;
h[++dh]=n;
poz[n]=dh;
c=dh;
p=c/2;
while(p>0){
if(a[h[p]]>a[h[c]]){
aux=h[p];
h[p]=h[c];
h[c]=aux;
poz[h[p]]=p;
poz[h[c]]=c;
}else
break;
c=p;
p/=2;
}
}
if(op==2){
in>>x;
a[x]=-1;
c=poz[x];
p=c/2;
while(p>0){
if(a[h[p]]>a[h[c]]){
aux=h[p];
h[p]=h[c];
h[c]=aux;
poz[h[p]]=p;
poz[h[c]]=c;
}
c=p;
p/=2;
}
h[1]=h[dh];
poz[h[1]]=1;
dh--;
p=1;
c=2;
if(c+1<=dh && a[h[c+1]]<a[h[c]])
c++;
while(c<=dh && a[h[p]]>a[h[c]]){
aux=h[p];
h[p]=h[c];
h[c]=aux;
poz[h[p]]=p;
poz[h[c]]=c;
}
p=c;
c*=2;
}
}
return 0;
}