New paste Repaste Download
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
namespace my {
template <typename KeyType, typename ValType>
class MinHeap {
    struct Entry { KeyType k; ValType v; };
public:
    MinHeap() : cap(0), size(0), arr(nullptr) {}
    ~MinHeap() {
        delete[] arr;
    }
    void push(const KeyType& key, const ValType& value) {
        if ( size == cap ) { expand(); }
        arr[size] = {key, value};
        sift_up(size);
        ++size;
    }
    ValType top() {
        return arr[0].v;
    }
    void pop(void) {
        if (size == 0) return;
        --size;
        std::swap(arr[0], arr[size]);
        sift_down(0);
    }
    bool empty() const {
        return size == 0;
    }
    size_t get_size() {
        return size;
    }
private:
    size_t size;
    size_t cap;
    Entry *arr;
    void expand () {
        size_t new_cap;
        if (cap == 0) {
             new_cap = 1;
        } else {
             new_cap = cap * 2;
        }
        Entry* tmp = new Entry[new_cap];
        for (size_t i = 0; i < size; i++) {
            tmp[i] = arr[i];
        }
        delete[] arr;
        arr = tmp;
        cap = new_cap;
    }
    void sift_up(size_t i) {
        while (i > 0) {
            size_t p = (i - 1) / 2;
            if (arr[p].k <= arr[i].k) break;
            std::swap(arr[p], arr[i]);
            i = p;
        }
    }
    void sift_down(uint32_t i) {
        while (true) {
            size_t l_idx = i * 2 + 1;
            size_t r_idx = l_idx + 1;
            size_t min_idx = i;
            if (l_idx < size && arr[min_idx].k > arr[l_idx].k) {
                min_idx = l_idx;
            }
            if (r_idx < size && arr[min_idx].k > arr[r_idx].k) {
                min_idx = r_idx;
            }
            if (min_idx == i) break;
            std::swap(arr[i], arr[min_idx]);
            i = min_idx;
        }
    }
};
}
void solve() {
    int q;
    std::cin >> q;
    my::MinHeap<int, int> min_heap;
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int val;
            cin >> val;
            min_heap.push(val, val);
        } else {
            if (!min_heap.empty()) {
                min_heap.pop();
            }
        }
        if (!min_heap.empty()) {
            cout << min_heap.top() << " ";
        } else {
            cout << -1 << " ";
        }
    }
    cout << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while (t--) {
        solve();
    }
}
Filename: main.cpp. Size: 3kb. View raw, , hex, or download this file.

This paste expires on 2026-01-10 12:52:59.401481+00:00. Pasted through v1-api.