Pagini recente » Cod sursa (job #312211) | Cod sursa (job #600349) | tema | Cod sursa (job #2742507)
#include <bits/stdc++.h>
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
int main() {
int order[1000000];
int n,j=1;
vector<int> heap;
make_heap(heap.begin(),heap.end());
f>>n;
for(int i=0;i<n;i++)
{
int op,value;
f>>op;
if(op==1)
{
f>>value;
heap.push_back((-1)*value);
push_heap(heap.begin(), heap.end());
order[j++] = value;
}
else if(op==2)
{
f>>value;
value = order[value];
vector<int>::iterator it;
for(auto it = heap.begin(); it != heap.end(); ++it)
{
if(*it == (-1)*value)
{
heap.erase(it);
push_heap(heap.begin(),heap.end());
break;
}
}
}
else if(op==3)
{
g<<(-1)*heap.front()<<'\n';
}
}
return 0;
}