Language: C++

#include <bits/stdc++.h>
using namespace std;
static const int N = 1e5 + 4;
static const int LN = 19;

int mx, my, n;

inline int get_point(int x, int y)
{
    if (y == 0) return x;
    if (x == mx) return mx + y;
    if (y == my) return mx + my + (mx - x);
    if (x == 0) return mx + my + mx + (my - y);
    return -1;
}

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}

typedef pair<int, int> num;
vector<num> c;
map<int, int> dis;

int a[N * 2];

struct rmq 
{
    int min[LN][N * 2], max[LN][N * 2];
    inline void build(int n, int *a) 
    {
        for (int i = 0; i < n; i ++) min[0][i] = max[0][i] = a[i];
        for (int j = 1; j < LN; j ++)
            for (int i = 0; i < n - (1 << j); i ++) 
            {
                max[j][i] = max(max[j - 1][i], max[j - 1][i + (1 << (j - 1))]);
                min[j][i] = min(min[j - 1][i], min[j - 1][i + (1 << (j - 1))]);
            }
    }
    inline pair<int, int> query(int l, int r) 
    {
        if (l == r) return make_pair(min[0][l], max[0][l]);
        int sz = 8 * sizeof(int) - __builtin_clz(r - l) - 1;
        return make_pair
        (
            min(min[sz][l], min[sz][r - (1 << sz) + 1]),
            max(max[sz][l], max[sz][r - (1 << sz) + 1])
        );
    }
}rmq;

int main()
{
   	mx = read();
   	my = read();
   	n = read();
    for (int i = 0, x1, y1, x2, y2; i < n; ++i) 
    {
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        int p1 = get_point(x1, y1),
            p2 = get_point(x2, y2);
        if (p1 != -1 && p2 != -1) 
        {
            if (p1 > p2) swap(p1, p2);
            c.push_back(num(p1, p2));
            dis.insert(make_pair(p1, 0));
            dis.insert(make_pair(p2, 0));
        }
    }
    int ct = 0;
    for (auto &kv : dis) kv.second = ct++;
    for (auto &p : c) {
        p.first = dis[p.first], p.second = dis[p.second];
        a[p.first] = p.second;
        a[p.second] = p.first;
    }
    rmq.build(ct, a);

    sort(c.begin(), c.end());
    for (auto p : c) if (p.second >= p.first + 2) 
    {
        auto val = rmq.query(p.first + 1, p.second - 1);
        if (val.first < p.first || val.second > p.second) 
        {
            puts("NO"); 
            return 0;
        }
    }

    puts("YES"); return 0;
}


Compiler output:
a.cc: In member function 'void rmq::build(int, int*)':
a.cc:40:32: error: expression cannot be used as a function
   40 |                 max[j][i] = max(max[j - 1][i], max[j - 1][i + (1 << (j - 1))]);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:41:32: error: expression cannot be used as a function
   41 |                 min[j][i] = min(min[j - 1][i], min[j - 1][i + (1 << (j - 1))]);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'std::pair<int, int> rmq::query(int, int)':
a.cc:50:16: error: expression cannot be used as a function
   50 |             min(min[sz][l], min[sz][r - (1 << sz) + 1]),
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:51:16: error: expression cannot be used as a function
   51 |             max(max[sz][l], max[sz][r - (1 << sz) + 1])
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~