Pagini recente » Cod sursa (job #2222216) | Rating Mieila Eduard Robert (eduard.mieila) | Istoria paginii info-oltenia-2019/echipe/solutii | Cod sursa (job #39976) | Cod sursa (job #2801091)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#define INF 100000
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
struct imp
{
int h,v;
};
int n,q,a,nr,l,orm,elm,poz[200001];
vector <int> heap;
bool cmp (int a,int b)
{
if (poz[a]<poz[b])
return 1;
else return 0;
}
bool minn (int a,int b)
{
if (a>b)
return 0;
else return 1;
}
int main()
{
f>>n;
make_heap(heap.begin(),heap.end(),minn);
for (int i=1; i<=n; i++)
{
f>>q;
//cout<<i<<' ';
if (q==1)
{
f>>a;
nr++;
heap.push_back(nr);
poz[nr]=a;
push_heap(heap.begin(),heap.end());
//cout<<nr<<' '<<a<<'\n';
/*nr++;
l++;
val[l].v=a;
val[nr].h=nr;
push(nr);*/
}
else if (q==2)
{
f>>a;
int ppoz=lower_bound(heap.begin(),heap.end(),a)-heap.begin();
//heap.erase(heap.begin()+poz);
heap[ppoz]=INF;
poz[heap[ppoz]]=INF;
//heap.erase(heap.begin()+a-1);
pop_heap(heap.begin(),heap.end());
/*int ok=0;
for (int j=1; j<=nr && ok==0; j++)
{
//cout<<h[j]<<' '<<j<<'\n';
if (val[j].h==a)
{
imp aux=val[j];
ok=1;
val[j]=val[nr];
val[nr]=aux;
}
}
nr--;
//push(nr);
pop(1);*/
//cout<<afis[a]<'\n';
}
else
{
int min1=INF;
for (int j=0; j<heap.size(); j++)
{
if (min1>poz[heap[j]])
min1=poz[heap[j]];
}
//sort_heap(heap.begin(),heap.end(),cmp);
g<<min1<<'\n';
//make_heap(heap.begin(),heap.end(),minn);
}
// sort_heap(heap.begin(),heap.end(),cmp);
}
return 0;
}