Pagini recente » Cod sursa (job #191551) | Cod sursa (job #2616129) | Cod sursa (job #111385) | Cod sursa (job #1297485) | Cod sursa (job #2191649)
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
int N,k,c[1000001],l;
vector <int> v;
void ad_heap(int x)
{
v.push_back(x);
k=v.size()-1;
l=l+1;
c[l]=k;
while(v[k]<v[k/2])
{swap(v[k/2],v[k]);
for(int j=1;j<l;j++)
if(c[j]==k/2)
swap(c[l],c[j]);
k=k/2;
}
}
void delet(int poz,int y)
{
swap(v[poz],v[v.size()-1]);
v.pop_back();
while(v[poz]<v[poz/2])
{swap(v[poz/2],v[poz]);
poz=poz/2;
}
while(poz<v.size()&&v[poz]>=v[2*poz]&&v[poz]>=v[2*poz+1])
if(v[2*poz]<=v[2*poz+1])
swap(v[poz],v[2*poz]);
else swap(v[poz],v[2*poz+1]);
c[y]=-1;
}
int main()
{ int x,y;
f>>N;
for(int i=1;i<=N;i++)
{
f>>x;
if(x==1)
{
f>>y;
ad_heap(y);
}
else if(x==2)
{ f>>y;
delet(c[y],y);
}
else g<<v[0]<<endl;
}
return 0;
}