func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   struct Block {     vector<array<int, 3>> events;     int pop_before;     vector<int> stack_after;     void add_event(array<int, 3> v) {       events.insert(upper_bound(events.begin(), events.end(), v), v);       sort(events.begin(), events.end());       pop_before = 0;       stack_after.clear();       for (auto [p, t, x] : events) {         if (t)           stack_after.push_back(x);         else {           if (stack_after.size())             stack_after.pop_back();           else             ++pop_before;         }       }     }   };   int main() {     cin.tie(0)->sync_with_stdio(0);     int q;     cin >> q;     int R = (int)sqrt(q);     int B = (q + R - 1) / R;     vector<Block> blocks(B);     for (int qq = 0; qq < q; ++qq) {       int p, t, x = 0;       cin >> p >> t;       --p;       if (t == 1) cin >> x;       blocks[p / R].add_event({p, t, x});       vector<array<int, 2>> remaining;       for (int i = 0; i < B; ++i) {         int to_pop = blocks[i].pop_before;         while (to_pop && remaining.size()) {           int pop_here = min(remaining.back()[0], to_pop);           to_pop -= pop_here;           remaining.back()[0] -= pop_here;           if (remaining.back()[0] == 0) remaining.pop_back();         }         if (blocks[i].stack_after.size())           remaining.push_back({(int)blocks[i].stack_after.size(), i});       }       if (remaining.size()) {         cout << blocks[remaining.back()[1]].stack_after[remaining.back()[0] - 1]              <<   n ;       } else         cout <<  -1 n ;     }   }   