Language: C++

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

#define endl '\n'
#define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL);

const int mx = 2e5 + 9;

int row[mx], col[mx];
int r_tree[4 * mx], c_tree[4 * mx];
int lazy_r[4 * mx], lazy_c[4 * mx];

void build_rtree(int node, int l, int r) {
    int mid = (l + r) / 2;
    int left = 2 * node;
    int right = left + 1;

    if (l == r) {
        r_tree[node] = row[l];
        return;
    }

    build_rtree(left, l, mid);
    build_rtree(right, mid + 1, r);

    r_tree[node] = min(r_tree[left], r_tree[right]);
}

void build_ctree(int node, int l, int r) {
    int mid = (l + r) / 2;
    int left = 2 * node;
    int right = left + 1;

    if (l == r) {
        c_tree[node] = col[l];
        return;
    }

    build_ctree(left, l, mid);
    build_ctree(right, mid + 1, r);

    c_tree[node] = min(c_tree[left], c_tree[right]);
}

void update_r(int node, int l, int r, int L, int R, int x) {
    int mid = (l + r) / 2;
    int left = 2 * node;
    int right = left + 1;

    if (lazy_r[node]) {
        r_tree[node] = min(r_tree[node], lazy_r[node]);
        if (lazy_r[left]) lazy_r[left] = min(lazy_r[left], lazy_r[node]);
        else lazy_r[left] = x;

        if (lazy_r[right]) lazy_r[right] = min(lazy_r[right], lazy_r[node]);
        else lazy_c[right] = x;

        lazy_r[node] = 0;
    }

    if (r < L or R < l) return;
    if (L <= l and r <= R) {
        r_tree[node] = min(r_tree[node], x);
        if (lazy_r[left]) lazy_r[left] = min(lazy_r[left], x);
        else lazy_r[left] = x;

        if (lazy_r[right]) lazy_r[right] = min(lazy_r[right], x);
        else lazy_r[right] = x;
        return;
    }

    update_r(left, l, mid, L, R, x);
    update_r(right, mid + 1, r, L, R, x);

    r_tree[node] = min(r_tree[left], r_tree[right]);
}

void update_c(int node, int l, int r, int L, int R, int x) {
    int mid = (l + r) / 2;
    int left = 2 * node;
    int right = left + 1;

    if (lazy_c[node]) {
        c_tree[node] = min(c_tree[node], lazy_c[node]);
        if (lazy_c[left]) lazy_c[left] = min(lazy_c[left], lazy_c[node]);
        else lazy_c[left] = x;

        if (lazy_c[right]) lazy_c[right] = min(lazy_c[right], lazy_c[node]);
        else lazy_c[right] = x;

        lazy_c[node] = 0;
    }

    if (r < L or R < l) return;
    if (L <= l and r <= R) {
        c_tree[node] = min(c_tree[node], x);
        if (lazy_c[left]) lazy_c[left] = min(lazy_c[left], x);
        else lazy_c[left] = x;

        if (lazy_c[right]) lazy_c[right] = min(lazy_c[right], x);
        else lazy_c[right] = x;
        return;
    }

    update_c(left, l, mid, L, R, x);
    update_c(right, mid + 1, r, L, R, x);

    c_tree[node] = min(c_tree[left], c_tree[right]);
}

int qry_r(int node, int l, int r, int L, int R, int x) {
    int mid = (l + r) / 2;
    int left = 2 * node;
    int right = left + 1;

    if (lazy_r[node]) {
        r_tree[node] = min(r_tree[node], lazy_r[node]);
        if (lazy_r[left]) lazy_r[left] = min(lazy_r[left], lazy_r[node]);
        else lazy_r[left] = lazy[node];

        if (lazy_r[right]) lazy_r[right] = min(lazy_r[right], lazy_r[node]);
        else lazy_c[right] = lazy[node];

        lazy_r[node] = 0;
    }

    if (r < L or R < l) return mx;
    if (L <= l and r <= R) {
        return r_tree[node];
    }

    int q1 = qry_r(left, l, mid, L, R);
    int q2 = qry_r(right, mid + 1, r, L, R);

    return min(q1, q2);
}

int qry_c(int node, int l, int r, int L, int R) {
    int mid = (l + r) / 2;
    int left = 2 * node;
    int right = left + 1;

    if (lazy_c[node]) {
        c_tree[node] = min(c_tree[node], lazy_c[node]);
        if (lazy_c[left]) lazy_c[left] = min(lazy_c[left], lazy_c[node]);
        else lazy_c[left] = lazy[node];

        if (lazy_c[right]) lazy_c[right] = min(lazy_c[right], lazy_c[node]);
        else lazy_c[right] = lazy[node];

        lazy_c[node] = 0;
    }

    if (r < L or R < l) return mx;
    if (L <= l and r <= R) {
        return c_tree[node];
    }

    int q1 = qry_c(left, l, mid, L, R);
    int q2 = qry_c(right, mid + 1, r, L, R);

    return min(q1, q2);
}

int main() {
    FIO();

    int n, q; cin >> n >> q;
    for (int i = 1; i < n; i++) row[i] = n;
    for (int i = 1; i < n; i++) col[i] = n;
    row[n] = col[n] = 1;

    build_rtree(1, 1, n);
    build_ctree(1, 1, n);   
}

Compiler output:
a.cc: In function 'int qry_r(int, int, int, int, int, int)':
a.cc:121:29: error: 'lazy' was not declared in this scope; did you mean 'lazy_r'?
  121 |         else lazy_r[left] = lazy[node];
      |                             ^~~~
      |                             lazy_r
a.cc:124:30: error: 'lazy' was not declared in this scope; did you mean 'lazy_r'?
  124 |         else lazy_c[right] = lazy[node];
      |                              ^~~~
      |                              lazy_r
a.cc:134:19: error: too few arguments to function 'int qry_r(int, int, int, int, int, int)'
  134 |     int q1 = qry_r(left, l, mid, L, R);
      |              ~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:113:5: note: declared here
  113 | int qry_r(int node, int l, int r, int L, int R, int x) {
      |     ^~~~~
a.cc:135:19: error: too few arguments to function 'int qry_r(int, int, int, int, int, int)'
  135 |     int q2 = qry_r(right, mid + 1, r, L, R);
      |              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:113:5: note: declared here
  113 | int qry_r(int node, int l, int r, int L, int R, int x) {
      |     ^~~~~
a.cc: In function 'int qry_c(int, int, int, int, int)':
a.cc:148:29: error: 'lazy' was not declared in this scope; did you mean 'lazy_r'?
  148 |         else lazy_c[left] = lazy[node];
      |                             ^~~~
      |                             lazy_r
a.cc:151:30: error: 'lazy' was not declared in this scope; did you mean 'lazy_r'?
  151 |         else lazy_c[right] = lazy[node];
      |                              ^~~~
      |                              lazy_r