Pagini recente » Cod sursa (job #1973642) | Cod sursa (job #2910952) | Cod sursa (job #2094613) | Cod sursa (job #2789291) | Cod sursa (job #1873730)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int h[200001],n,t,k,nr,a[200001],p,ct;
void Comb(int i)
{
int v=h[i],tata=i,fiu=2*i;
while(fiu<=ct)
{
if(fiu<ct)
if(h[fiu]>h[fiu+1])
fiu++;
if(v>h[fiu])
{
h[tata]=h[fiu];
tata=fiu;
fiu=2*fiu;
}
else
fiu=ct+1;
}
h[tata]=v;
}
void InvComb(int x)
{
int v=h[x];
while(x>1&&v<h[x/2])
{
h[x]=h[x/2];
x=x/2;
}
h[x]=v;
}
void inserare(int x)
{
h[++ct]=x;
InvComb(x);
}
void stergere(int x)
{
h[x]=h[ct];
--ct;
if(x>1&&h[x]<h[x/2])
InvComb(x);
else
Comb(x);
}
int main()
{
int i,v,j;
fin>>n;
for(i=1;i<=n;i++)
{
fin>>t;
if(t==1)
{
fin>>k;
a[++nr]=k;
inserare(k);
}
else if(t==2)
{
fin>>k;
for(j=1;j<=ct;j++)
if(a[j]==a[k])
{
p=j;
break;
}
stergere(p);
}
else
{
fout<<h[1]<<"\n";
}
}
return 0;
}