Pagini recente » Cod sursa (job #478535) | Cod sursa (job #2617374) | Cod sursa (job #2854073) | Clasament preoji_4 | Cod sursa (job #1821727)
#include <fstream>
#include <cmath>
#define nmax 200005
#define nt 10000;
using namespace std;
ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");
long long int heap[nmax],nod[nmax],poz[nmax], n;
void verif(int k)
{
int fiu=heap[k];
int fiuviz=k;
while((fiu<heap[k/2])and(fiu and heap[k/2]))
{
heap[k]=heap[k/2];
poz[heap[k]]=k;
k=k/2;
}
heap[k]=fiu;
poz[heap[k]]=k;
}
int main()
{
int k=0;
fin>>n;
for(int i=1;i<=n;i++)
{
int x, y;
fin>>x;
if(x==1)
{
fin>>y;
nod[++k]=y;
heap[k]=y;
poz[y]=k;
verif(k);
}
else if(x==2)
{
fin>>y;
heap[poz[nod[y]]]=nt;
int z;
if(heap[poz[nod[y]]*2])
z=poz[nod[y]]*2;
if(heap[poz[nod[y]]*2]>heap[poz[nod[y]]*2+1] and heap[poz[nod[y]]*2+1])
z=poz[nod[y]]*2+1;
verif(z);
}
else if(x==3)
fout<<heap[1]<<'\n';
}
return 0;
}