Pagini recente » Cod sursa (job #1935919) | Cod sursa (job #821321) | Cod sursa (job #2830888) | Cod sursa (job #2138250) | Cod sursa (job #3264952)
#include <bits/stdc++.h>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
struct cv {
int x;
int time;
};
int q;
vector<cv> heap;
bool cmp(const cv& a, const cv& b) {
return a.x > b.x;
}
void push(const cv& elem) {
heap.push_back(elem);
push_heap(heap.begin(),heap.end(),cmp);
}
void pop(const int time) {
int i = 0;
while (heap[i].time != time) {
i++;
}
swap(heap[i],heap.back());
heap.pop_back();
make_heap(heap.begin(),heap.end(),cmp);
}
int main() {
fin >> q;
int time = 1;
while (q--) {
int t;
fin >> t;
switch (t) {
case 1: {
int x;
fin >> x;
const cv temp = {x,time};
push(temp);
time++;
break;
}
case 2: {
int x;
fin >> x;
pop(x);
break;
}
case 3: {
fout << heap.front().x << '\n';
break;
}
}
}
return 0;
}