Language: C++

int main() {
    PRE_COMMAND
    int h, w, end, start, a, b, m, lim = 0, inf = pow(10, 9), ini;
    INPUT(h, w);
    map<int, int> end_start;
    multiset<int> mset;
    mset.insert(inf);
    REP(i, w) {
        end_start[i] = i;
        mset.insert(0);
    }
    vector<tuple<int, int>> temp;
    for (int i = 0; i < h; i++) {
        INPUT(a, b);
        temp = {};
        m = -1, ini = -1;
        for (auto itr = end_start.lower_bound(a - 1);
             itr != end_start.upper_bound(b - 1); itr++) {
            tie(end, start) = *itr;
            temp.push_back(*itr);
            ini = max(ini, start);
            m = max(m, end);
        }
        for (auto t : temp) {
            tie(end, start) = t;
            end_start.erase(end);
            mset.erase(mset.find(end - start));
            // PRINT(end, start);
        }
        if (b < w && ini != -1 && end_start.count(b) == 0) {
            end_start[b] = ini;
            mset.insert(b - ini);
            // PRINT("", b, ini);
        }
        // PRINT(mset.size());
        if (MIN(mset) == inf) {
            PRINT(-1);
        } else {
            PRINT(MIN(mset) + i + 1);
        }
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:2:5: error: 'PRE_COMMAND' was not declared in this scope
    2 |     PRE_COMMAND
      |     ^~~~~~~~~~~
a.cc:4:11: error: 'h' was not declared in this scope
    4 |     INPUT(h, w);
      |           ^
a.cc:4:14: error: 'w' was not declared in this scope
    4 |     INPUT(h, w);
      |              ^
a.cc:4:5: error: 'INPUT' was not declared in this scope
    4 |     INPUT(h, w);
      |     ^~~~~
a.cc:5:5: error: 'map' was not declared in this scope
    5 |     map<int, int> end_start;
      |     ^~~
a.cc:5:9: error: expected primary-expression before 'int'
    5 |     map<int, int> end_start;
      |         ^~~
a.cc:6:5: error: 'multiset' was not declared in this scope
    6 |     multiset<int> mset;
      |     ^~~~~~~~
a.cc:6:14: error: expected primary-expression before 'int'
    6 |     multiset<int> mset;
      |              ^~~
a.cc:7:5: error: 'mset' was not declared in this scope
    7 |     mset.insert(inf);
      |     ^~~~
a.cc:7:17: error: 'inf' was not declared in this scope; did you mean 'int'?
    7 |     mset.insert(inf);
      |                 ^~~
      |                 int
a.cc:8:9: error: 'i' was not declared in this scope
    8 |     REP(i, w) {
      |         ^
a.cc:8:5: error: 'REP' was not declared in this scope
    8 |     REP(i, w) {
      |     ^~~
a.cc:12:5: error: 'vector' was not declared in this scope
   12 |     vector<tuple<int, int>> temp;
      |     ^~~~~~
a.cc:12:12: error: 'tuple' was not declared in this scope
   12 |     vector<tuple<int, int>> temp;
      |            ^~~~~
a.cc:12:18: error: expected primary-expression before 'int'
   12 |     vector<tuple<int, int>> temp;
      |                  ^~~
a.cc:14:15: error: 'a' was not declared in this scope
   14 |         INPUT(a, b);
      |               ^
a.cc:14:18: error: 'b' was not declared in this scope
   14 |         INPUT(a, b);
      |                  ^
a.cc:15:9: error: 'temp' was not declared in this scope
   15 |         temp = {};
      |         ^~~~
a.cc:16:9: error: 'm' was not declared in this scope
   16 |         m = -1, ini = -1;
      |         ^
a.cc:16:17: error: 'ini' was not declared in this scope; did you mean 'int'?
   16 |         m = -1, ini = -1;
      |                 ^~~
      |                 int
a.cc:17:25: error: 'end_start' was not declared in this scope
   17 |         for (auto itr = end_start.lower_bound(a - 1);
      |                         ^~~~~~~~~
a.cc:19:17: error: 'end' was not declared in this scope
   19 |             tie(end, start) = *itr;
      |                 ^~~
a.cc:19:22: error: 'start' was not declared in this scope
   19 |             tie(end, start) = *itr;
      |                      ^~~~~
a.cc:19:13: error: 'tie' was not declared in this scope
   19 |             tie(end, start) = *itr;
      |             ^~~
a.cc:21:19: error: 'max' was not declared in this scope
   21 |             ini = max(ini, start);
      |                   ^~~
a.cc:25:17: error: 'end' was not declared in this scope
   25 |             tie(end, start) = t;
      |                 ^~~
a.cc:25:22: error: 'start' was not declared in this scope
   25 |             tie(end, start) = t;
      |                      ^~~~~
a.cc:25:13: error: 'tie' was not declared in this scope
   25 |             tie(end, start) = t;
      |             ^~~
a.cc:26:13: error: 'end_start' was not declared in this scope
   26 |             end_start.erase(end);
      |             ^~~~~~~~~
a.cc:30:35: error: 'end_start' was not declared in this scope
   30 |         if (b < w && ini != -1 && end_start.count(b) == 0) {
      |                                   ^~~~~~~~~
a.cc:36:13: error: 'MIN' was not declared in this scope
   36 |         if (MIN(mset) == inf) {
      |             ^~~
a.cc:37:13: error: 'PRINT' was not declared in this scope
   37 |             PRINT(-1);
      |             ^~~~~
a.cc:39:13: error: 'PRINT' was not declared in this scope
   39 |             PRINT(MIN(mset) + i + 1);
      |             ^~~~~