ldqdoj connected

09/06/2024

bla bla

Code
//                                   ___-------___
//                               _-~~             ~~-_
//                            _-~                    /~-_
//         /^\__/^\         /~  \                   /    \
//       /  O|| O|        /      \_______________/        \
//      | |___||__|      /       /                \          \
//      |          \    /      /                    \          \
//      |   (_______) /______/                        \_________ \
//      |         / /         \                      /            \
//       \         \^\         \                  /               \     /
//         \         ||           \______________/      _-_       //\__//
//           \       ||------_-~~-_ ------------- \ --/~   ~\    || __/
//             ~-----||====/~     |==================|       |/~~~~~
//              (_(__/  ./     /                    \_\      \.
//                     (_(___/                         \_____)_)
//
// I'm Turtle, I'm slow

#include             <bits/stdc++.h>
#define pb           push_back
#define fi           first
#define se           second
#define int          long long
#define pii          pair<long long, long long>
#define endl         "\n"
#define TIME         (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i)      (1ll<<(i))
#define FILE(A)      freopen(A".INP", "r", stdin); freopen(A".OUT", "w", stdout)
#define BIT(Mask, i) (((Mask)>>(i))&1)
#define piii pair<pii, int>

using namespace std;

const int N    = 1e5+5;
const int MOD  = 1e9+7;
const int INF  = 1e16 ;
const int Lim  = 1e9  ;
const int BASE = 31   ;

int R, C, n;
vector<piii> pt;
int x[N], y[N];

bool inside(int x, int y) {
    return (1 <= x && x < R && 1 <= y && y < C);
}
bool check() {
    for (int i=1;i <= 2;i++) {
        if (inside(x[i], y[i]))
            return false;
    }
    return true;
}

int dist(pii x) {
    if (!x.fi) {
        return x.se;
    }
    if (x.se == C) {
        return C + x.fi;
    }
    if (x.fi == R) {
        return C + R + (C - x.se);
    }
    return R + C + R + (C - x.fi);
}


bool cmp(piii a, piii b) {
    return (dist(a.fi) < dist(b.fi));
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> R >> C >> n;
    for (int j=1;j <= n;j++) {
        for (int i=1;i <= 2;i++) {
            cin >> x[i] >> y[i];
        }
        if(check()) {
            for (int i=1; i <= 2;i++) {
                pt.pb({{x[i], y[i]}, j});
            }
        }
    }
    sort(pt.begin(), pt.end(), cmp);
    stack<int> s;
    for (auto i : pt) {
        int color = i.se;
        if (s.empty())
            s.push(color);
        else if (s.top() == color)
            s.pop();
        else s.push(color);
    }
    cout << (!s.empty() ? "NO" : "YES");



    return 0;
}

// Nguyen Minh Hieu - 2008 - Gia Lai.
// https://hieuhfgr.pythonanywhere.com/
// .-.. --- ...- . .-.. -.--