Pagini recente » Cod sursa (job #1113708) | Cod sursa (job #1994171) | Cod sursa (job #2958524) | Cod sursa (job #2069499) | Cod sursa (job #3168367)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("heapuri.in");
ofstream g ("heapuri.out");
struct heap{
int val, poz;
bool operator < (const heap other) const{
return val > other.val;
}
};
const int NMAX = 2e5;
priority_queue<heap> q;
bool marked[NMAX+1];
void update(int val, int poz){
heap x;
x.val = val;
x.poz = poz;
q.push(x);
}
void sterge(int poz){
marked[poz] = true;
}
void top(){
while(!q.empty() and marked[q.top().poz])
q.pop();
if(!q.empty())
g << q.top().val <<"\n";
}
int main()
{
int t;
f >> t;
int cnt = 0;
for(int i=1; i<=t; i++){
int c;
f >> c;
if(c == 3)
top();
else{
int val;
f >> val;
if(c == 1)
cnt ++, update(val, cnt);
if(c == 2)
sterge(val);
}
}
return 0;
}