Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;

int main(){
  using namespace std;
  int r,c,n;
  cin>>r>>c>>n;
  int x[n][2], y[n][2];
  REP(i,n){
    cin>>x[i][0]>>y[i][0]>>x[i][1]>>y[i][1];
  }
  typedef pair<int, int> P;
  vector<pair<P, int>> ue, re, de, le;
  REP(i,n){
    if(x[i][0] == 0 && x[i][1] == r){
      ue.push_back(make_pair(P(x[i][1], y[i][1]), i));
      de.push_back(make_pair(P(x[i][0], y[i][0]), i));
    }else if(x[i][0] == r && x[i][1] == 0){
      ue.push_back(make_pair(P(x[i][0], y[i][0]), i));
      de.push_back(make_pair(P(x[i][1], y[i][1]), i));
    }else if(y[i][0] == 0 && y[i][1] == c){
      le.push_back(make_pair(P(x[i][0], y[i][0]), i));
      re.push_back(make_pair(P(x[i][1], y[i][1]), i));
    }else if(y[i][0] == c && y[i][1] == 0){
      le.push_back(make_pair(P(x[i][1], y[i][1]), i));
      re.push_back(make_pair(P(x[i][0], y[i][0]), i));
    }else{
      continue;
    }
  }
  sort(ALL(ue));
  sort(ALL(re), greater<pair<int, P>>());
  sort(ALL(de), greater<pair<int, P>>());
  sort(ALL(le));
  stack<int> st;
  for(auto p:ue){
    int now = st.top();
    if(now == p.second.second){
      st.pop();
    }else{
      st.push(p.second.second);
    }
  }
  for(auto p:re){
    int now = st.top();
    if(now == p.second.second){
      st.pop();
    }else{
      st.push(p.second.second);
    }
  }
  for(auto p:de){
    int now = st.top();
    if(now == p.second.second){
      st.pop();
    }else{
      st.push(p.second.second);
    }
  }
  for(auto p:le){
    int now = st.top();
    if(now == p.second.second){
      st.pop();
    }else{
      st.push(p.second.second);
    }
  }
  if(st.size() == 0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0; 
}


Compiler output:
a.cc: In function 'int main()':
a.cc:100:24: error: request for member 'second' in 'p.std::pair<std::pair<int, int>, int>::second', which is of non-class type 'int'
  100 |     if(now == p.second.second){
      |                        ^~~~~~
a.cc:103:24: error: request for member 'second' in 'p.std::pair<std::pair<int, int>, int>::second', which is of non-class type 'int'
  103 |       st.push(p.second.second);
      |                        ^~~~~~
a.cc:108:24: error: request for member 'second' in 'p.std::pair<std::pair<int, int>, int>::second', which is of non-class type 'int'
  108 |     if(now == p.second.second){
      |                        ^~~~~~
a.cc:111:24: error: request for member 'second' in 'p.std::pair<std::pair<int, int>, int>::second', which is of non-class type 'int'
  111 |       st.push(p.second.second);
      |                        ^~~~~~
a.cc:116:24: error: request for member 'second' in 'p.std::pair<std::pair<int, int>, int>::second', which is of non-class type 'int'
  116 |     if(now == p.second.second){
      |                        ^~~~~~
a.cc:119:24: error: request for member 'second' in 'p.std::pair<std::pair<int, int>, int>::second', which is of non-class type 'int'
  119 |       st.push(p.second.second);
      |                        ^~~~~~
a.cc:124:24: error: request for member 'second' in 'p.std::pair<std::pair<int, int>, int>::second', which is of non-class type 'int'
  124 |     if(now == p.second.second){
      |                        ^~~~~~
a.cc:127:24: error: request for member 'second' in 'p.std::pair<std::pair<int, int>, int>::second', which is of non-class type 'int'
  127 |       st.push(p.second.second);
      |                        ^~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::pair<std::pair<int, int>, int>*, std::vector<std::pair<std::pair<int, int>, int> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::pair<std::pair<int, int>, int>*, std::vector<std::pair<std::pair<int, int>, int> > >; _Compare = std::greater<std::pair<int, std::pair<int, int> > >]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<greater<pair<int, pair<int, int> > > >]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<greater<pair<int, pair<int, int> > > >]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<greater<pair<int, pair<int, int> > > >]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = greater<pair<int, pair<int, int> > >]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:94:7:   required from here
   94 |   sort(ALL(re), greater<pair<int, P>>());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: no match for call to '(std::greater<std::pair<int, std::pair<int, int> > >) (std::pair<std::pair<int, int>, int>&, std::pair<std::pair<int, int>, int>&)'
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/stl_function.h:394:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = std::pair<int, std::pair<int, int> >]'
  394 |       operator()(const _Tp& __x, const _Tp& __y) const
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_function.h:394:29: note:   no known conversion for argument 1 from 'std::pair<std::pair<int, int>, int>' to 'const std::pair<int, std::pair<int, int> >&'
  394 |       operator()(const _Tp& __x, const _Tp& __y) const
      |                  ~~~~~~~~~~~^~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = std::pair<std::pair<int, int>, int>; _Iterator = __gnu_cxx::__normal_iterator<std::pair<std::pair<int, int>, int>*, std::vector<std::pair<std::pair<int, int>, int> > >; _Compare = std::greater<std::pair<int, std::pair<int, int> > >]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<greater<pair<int, pair<int, int> > > >]'
 1757 |       while (__comp(__val, __next))
      |              ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1785:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<greater<pair<int, pair<int, int> > > >]'
 1785 |             std::__unguarded_linear_insert(__i,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
 1786 |                                 __gnu_cxx::__ops::__val_comp_iter(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<greater<pair<int, pair<int, int> > > >]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<greater<pair<int, pair<int, int> > > >]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Compare = greater<pair<int, pair<int, int> > >]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:94:7:   required from here
   94 |   sort(ALL(re), greater<pair<int, P>>());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:240:30: error: no match for call to '(std::greater<std::pair<int, std::pair<int, int> > >) (std::pair<std::pair<int, int>, int>&, std::pair<std::pair<int, int>, int>&)'
  240 |         { return bool(_M_comp(__val, *__it)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:394:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = std::pair<int, std::pair<int, int> >]'
  394 |       operator()(const _Tp& __x, const _Tp& __y) const
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_function.h:394:29: note:   no known conversion for argument 1 from 'std::pair<std::pair<int, int>, int>' to 'const std::pair<int, std::pair<int, int> >&'
  394 |       operator()(const _Tp& __x, const _Tp& __y) const
      |                  ~~~~~~~~~~~^~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<std::pair<int, int>, int>*, std::vector<std::pair<std::pair<int, int>, int> > >; _Value = std::pair<std::pair<int, int>, int>; _Compare = std::greater<std::pair<int, std::pair<int, int> > >]':
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<int, int>, int>*, vector<pair<pair<int, int>, int> > >; _Distance = long int; _Tp = pair<pair<int, int>, int>; _Compare = __gnu_cxx::__ops::_Iter