Pagini recente » Cod sursa (job #1409606) | Cod sursa (job #1485346) | Cod sursa (job #1366597) | Cod sursa (job #1086842) | Cod sursa (job #1952152)
#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, next;
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;
if(vf==40)
continue;
}
else if(op==2)
{
fin>>who;
ac=poz[who];
aux=heap[lg--];
if(heap[2*ac].val>heap[2*ac+1].val)
next=2*ac+1;
else next=2*ac;
while(aux.val>heap[next].val && next<=lg)
{
heap[ac]=heap[next];
poz[heap[ac].ord]=ac;
ac=next;
if(heap[2*ac].val>heap[2*ac+1].val)
next=2*ac+1;
else next=2*ac;
}
heap[ac]=aux;
poz[heap[ac].ord]=ac;
}
else fout<<heap[1].val<<'\n';
}
return 0;
}