Pagini recente » Cod sursa (job #3234231) | Cod sursa (job #2253620) | Cod sursa (job #3182204) | Cod sursa (job #772334) | Cod sursa (job #3168363)
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
struct elem{
int val;
int poz;
bool operator < (elem other) const{
return val > other.val;
}
elem(int a, int b)
{
val=a;
poz=b;
}
};
const int nmax=2e5 + 1;
bool removed[nmax];
int main()
{
priority_queue<elem> heap;
int n;
fin >> n;
int op, x, cnt=1;
for(int i=0; i<n; i++)
{
fin >> op;
if(op==1)
{
fin >> x;
heap.push(elem(x, cnt++));
}
else if(op==2)
{
fin >> x;
removed[x]=1;
}
else
{
while(removed[heap.top().poz]) heap.pop();
fout << heap.top().val << '\n';
}
}
return 0;
}