Language: C++

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define Cerr(x) cerr << (x) << endl
#define fi first
#define se second
#define P pair<ll, ll>
#define m_p make_pair

ll n, cnt, ans, a, b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k, x2, y2;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};
pair<P, P> p[ohara];
ll p_cou;
ll dat1[ohara],dat2[ohara],dat3[ohara],dat4[ohara];

//-------------------------↓↓↓↓↓↓------------------------

bool border(ll nowy, ll nowx)
{
    if (nowy == 0 || nowx == 0)
        return true;
    else if (nowy == h || nowx == w)
        return true;
    else
        return false;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> h >> w >> n;
    rep(i, n)
    {
        cin >> y >> x >> y2 >> x2;
        dat1[i]=y;
        dat2[i]=x;
        dat3[i]=y2;
        dat4[i]=y2;
        if (!border(y, x) || !border(y2, x2))
            continue;
        if (y > y2)
        {
            swap(x, x2);
            swap(y, y2);
        }
        p[p_cou++] = m_p(m_p(x, -y), m_p(x2, -y2));
    }
    sort(p, p + p_cou);
    ll limx = -1, limy = -1;
    ll limx2 = -1, limy2 = -1;
    ll splimx1 = -1, splimx2 = -1, splimx3 = -1, splimx4 = -1, splimy1 = -1, splimy2 = -1, splimy3 = -1, splimy4 = -1;
    ll dec1, dec2;
    rep(i, p_cou)
    {
        if (p[i].fi.fi == p[i].se.fi)
        {
            if (p[i].fi.fi == 0)
            {
                if (splimy1 == -1)
                {
                    splimy1 = min(p[i].fi.se * -1, p[i].se.se * -1);
                    splimy2 = max(p[i].fi.se * -1, p[i].se.se * -1);
                }
                else
                {
                    if ((splimy1 <= p[i].fi.se * -1 && p[i].fi.se * -1 <= splimy2) || (splimy1 <= p[i].se.se * -1 && p[i].se.se * -1 <= splimy2))
                    {
                        Cout("NO");
                        return 0;
                    }
                    else
                    {
                        splimy1 = min(p[i].fi.se * -1, p[i].se.se * -1);
                        splimy2 = max(p[i].fi.se * -1, p[i].se.se * -1);
                    }
                }
            }
            else
            {
                if (splimy3 == -1)
                {
                    splimy3 = min(p[i].fi.se * -1, p[i].se.se * -1);
                    splimy4 = max(p[i].fi.se * -1, p[i].se.se * -1);
                }
                else
                {
                    if ((splimy3 <= p[i].fi.se * -1 && p[i].fi.se * -1 <= splimy4) || (splimy3 <= p[i].se.se * -1 && p[i].se.se * -1 <= splimy4))
                    {
                        Cout("NO");
                        return 0;
                    }
                    else
                    {
                        splimy3 = min(p[i].fi.se * -1, p[i].se.se * -1);
                        splimy4 = max(p[i].fi.se * -1, p[i].se.se * -1);
                    }
                }
            }
        } /////////////////
        else if (p[i].fi.se == p[i].se.se)
        {
            if (p[i].fi.se == 0)
            {
                if (splimx1 == -1)
                {
                    splimx1 = min(p[i].fi.fi, p[i].se.fi);
                    splimx2 = max(p[i].fi.fi, p[i].se.fi);
                }
                else
                {
                    if ((splimx1 <= p[i].fi.fi && p[i].fi.fi <= splimx2) || (splimx1 <= p[i].se.fi && p[i].se.fi <= splimx2))
                    {
                        Cout("NO");
                        return 0;
                    }
                    else
                    {
                        splimx1 = min(p[i].fi.fi, p[i].se.fi);
                        splimx2 = max(p[i].fi.fi, p[i].se.fi);
                    }
                }
            }
            else
            {
                if (splimx3 == -1)
                {
                    splimx3 = min(p[i].fi.fi, p[i].se.fi);
                    splimx4 = max(p[i].fi.fi, p[i].se.fi);
                }
                else
                {
                    if ((splimx3 <= p[i].fi.fi && p[i].fi.fi <= splimx4) || (splimx3 <= p[i].se.fi && p[i].se.fi <= splimx4))
                    {
                        Cout("NO");
                        return 0;
                    }
                    else
                    {
                        splimx3 = min(p[i].fi.fi, p[i].se.fi);
                        splimx4 = max(p[i].fi.fi, p[i].se.fi);
                    }
                }
            }
        }
        else
        {
            ///////////////////////
            if (splimx1 != -1)
            {
                if ((splimx1 <= p[i].fi.fi && p[i].fi.fi <= splimx2 && p[i].fi.se * -1 == 0) || (splimx1 <= p[i].se.fi && p[i].se.fi <= splimx2 && p[i].se.se * -1 == 0))
                {
                    Cout("NO");
                    return 0;
                }
            }
            if (splimx3 != -1)
            {
                if ((splimx3 <= p[i].fi.fi && p[i].fi.fi <= splimx4 && p[i].fi.se * -1 == h) || (splimx3 <= p[i].se.fi && p[i].se.fi <= splimx4 && p[i].se.se * -1 == h))
                {
                    //cerr<<splimx3<<" "<<splimx4<<" "<<p[i].fi.fi<<" "<<p[i].se.fi<<"\n";
                    Cout("NO");
                    return 0;
                }
            }
            if (splimy1 != -1)
            {
                if ((splimy1 <= p[i].fi.se * -1 && p[i].fi.se * -1 <= splimy2 && p[i].fi.fi == 0) || (splimy1 <= p[i].se.se * -1 && p[i].se.se * -1 <= splimy2 && p[i].se.fi == 0))
                {
                    Cout("NO");
                    return 0;
                }
            }
            if (splimy3 != -1)
            {
                if ((splimy3 <= p[i].fi.se * -1 && p[i].fi.se * -1 <= splimy4 && p[i].fi.fi == w) || (splimy3 <= p[i].se.se * -1 && p[i].se.se * -1 <= splimy4 && p[i].se.fi == w))
                {
                    Cout("NO");
                    return 0;
                }
            }
            ///////////////////////
            dec1 = 0;
            dec2 = 0;
            if (limx == -1 && p[i].fi.fi <= p[i].se.fi)
            {
                limx = p[i].se.fi;
                limy = p[i].fi.se * -1;
                dec1 = 1;
            }
            else if (limx2 == -1 && p[i].fi.fi > p[i].se.fi)
            {
                limx2 = p[i].fi.fi;
                limy2 = p[i].se.se * -1;
                dec2 = 1;
            }
            if (limx != -1 && dec1 == 0)
            {
                if ((p[i].se.fi < limx && p[i].se.se * -1 > limy) || ((p[i].fi.fi < limx && p[i].fi.se * -1 > limy)))
                {
                    Cout("NO");
                    return 0;
                }
            }
            else if (limx2 != -1 && dec2 == 0)
            {
                if ((p[i].se.fi < limx2 && p[i].se.se * -1 < limy) || (p[i].fi.fi < limx2 && p[i].fi.se * -1 < limy))
                {
                    Cout("NO");
                    return 0;
                }
            }
            if (p[i].fi.fi <= p[i].se.fi)
            {
                limx = p[i].se.fi;
                limy = p[i].fi.se * -1;
            }
            else if (p[i].fi.fi > p[i].se.fi)
            {
                limx2 = p[i].fi.fi;
                limy2 = p[i].se.se * -1;
            }
        }
        //cerr << limx << " " << limy << " " << limx2 << " " << limy2 << "\n";
    }
    rep(i,n){
        if (splimx1 != -1)
            {
                if ((splimx1 <= dat2[i] && dat2[i] <= splimx2 && dat1[i] == 0) || (splimx1 <= dat4[i] && dat4[i] <= splimx2 && dat[3] == 0))
                {
                    Cout("NO");
                    return 0;
                }
            }
            if (splimx3 != -1)
            {
                if ((splimx3 <= dat2[i] && dat2[i] <= splimx4 && dat1[i] == h) || (splimx3 <= dat4[i] && dat4[i] <= splimx4 && dat3[i] == h))
                {
                    //cerr<<splimx3<<" "<<splimx4<<" "<<p[i].fi.fi<<" "<<p[i].se.fi<<"\n";
                    Cout("NO");
                    return 0;
                }
            }
            if (splimy1 != -1)
            {
                if ((splimy1 <= dat1[i] && dat1[i] <= splimy2 && dat2[i] == 0) || (splimy1 <= dat3[i] && dat3[i] <= splimy2 && dat4[i] == 0))
                {
                    Cout("NO");
                    return 0;
                }
            }
            if (splimy3 != -1)
            {
                if ((splimy3 <= dat1[i] && dat1[i] <= splimy4 && dat2[i] == w) || (splimy3 <= dat3[i] && dat3[i] <= splimy4 && dat4[i] == w))
                {
                    Cout("NO");
                    return 0;
                }
            }
    }
    Cout("YES");
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:250:128: error: 'dat' was not declared in this scope; did you mean 'dat4'?
  250 |                 if ((splimx1 <= dat2[i] && dat2[i] <= splimx2 && dat1[i] == 0) || (splimx1 <= dat4[i] && dat4[i] <= splimx2 && dat[3] == 0))
      |                                                                                                                                ^~~
      |                                                                                                                                dat4