Pagini recente » Cod sursa (job #630634) | Cod sursa (job #723180) | Cod sursa (job #1424624) | Cod sursa (job #2512362) | Cod sursa (job #1952102)
#include <fstream>
using namespace std;
ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");
struct strheap
{
int val, ord;
};
int n;
int poz[200100];
strheap heap[200100];
int main()
{
int i, lg, vf, ac, who, op, cat;
strheap aux;
cat=lg=0;
fin>>n;
for(i=1; i<=n; ++i)
{
fin>>op;
if(op==1)
{
fin>>vf;
ac=++lg;
aux.ord=++cat;
aux.val=vf;
while( (ac/2)>=1 && aux.val<heap[ac/2].val )
{
heap[ac]=heap[ac/2];
poz[heap[ac].ord]=ac;
ac=ac/2;
}
heap[ac]=aux;
poz[heap[ac].ord]=ac;
}
else if(op==2)
{
fin>>who;
ac=poz[who];
aux=heap[lg--];
while(aux.val>heap[2*ac].val && 2*ac<=lg)
{
heap[ac]=heap[2*ac];
poz[heap[ac].ord]=ac;
ac=2*ac;
}
heap[ac]=aux;
poz[heap[ac].ord]=ac;
}
else fout<<heap[1].val<<'\n';
}
return 0;
}