Pagini recente » Cod sursa (job #3274768) | Cod sursa (job #166428) | Cod sursa (job #1628319) | Cod sursa (job #2215342) | Cod sursa (job #1836833)
#include <iostream>
#include <fstream>
#include <utility>
#include <vector>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
typedef pair<int,int> T;
vector<T> x;
vector<int> y;
void beszur(int uj,int sor)
{
x.push_back(T(uj,sor));
int aktpoz=x.size()-1;
y[sor]=aktpoz;
while(x[aktpoz/2].first>x[aktpoz].first)
{
swap(x[aktpoz/2],x[aktpoz]);
swap(y[x[aktpoz/2].second],y[x[aktpoz].second]);
aktpoz/=2;
}
}
void torol(int poz)
{
x[poz]=x.back();
y[x[poz].second]=poz;
x.pop_back();
int p=0;
while(p!=poz)
{
p=poz;
if(p*2<x.size() && x[p*2].first<x[poz].first) poz=p*2;
if(p*2+1<x.size() && x[p*2+1].first<x[poz].first) poz=p*2+1;
swap(x[poz],x[p]);
swap(y[x[poz].second],y[x[p].second]);
}
}
int mini()
{
return x[1].first;
}
int main()
{
int n,i,a,b,j,h;
int d=0;
fin>>n;
y.resize(n+1);
x.push_back(T(0,0));
for(i=1;i<=n;i++)
{
fin>>a;
if(a==1)
{
fin>>b;
d++;
beszur(b,d);
}
if(a==2)
{
fin>>b;
h=y[b];
torol(h);
}
if(a==3)
{
fout<<mini()<<"\n";
}
/* for(int j=1;j<=n;j++) if(x[j].second<10 && x[j].second>0)cout<<x[j].second<<" ";
cout<<"\n"; */
}
return 0;
}