Language: C++

// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair
 
 
int main(){
  LCIN(h,w,n);VC2(n,x1,y1,x2,y2);
  vector<P> v;
  REP(i,n){
    if(((x1[i]==0||x1[i]==h)||(y1[i]==0||y1[i]==w))&&((x2[i]==0||x2[i]==h)||(y2[i]==0||y2[i]==w))){
      ll v1,v2;
      v1 = (!y1[i]?x1[i]:(x1[i]==h?h+y1[i]:(y1[i]==w?h+w+h-x1[i]:w*2+h*2-y1[i])));
      v2 = (!y2[i]?x2[i]:(x2[i]==h?h+y2[i]:(y2[i]==w?h+w+h-x2[i]:w*2+h*2-y2[i])));
      P vv = mp(v1,v2);
      if(vv.first>vv.second)swap(vv.first,vv.second);
      v.pb(vv);
    }
  }
  sort(ALL(v));
  /*
  REP(i,v.size())
    cout<<v[i].first <<" : "<<v[i].second<<endl;
    */
  set<P> s;
  REP(i,v.size()){
      s.erase(s.begin(), s.upper_bound(v[i].first));
      if(s.upper_bound(v[i].second) != next(s.begin()))
        EN(NO);
    }
    s.insert(v[i]);
  }
  YES(1);
  
 
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:109:39: error: no matching function for call to 'std::set<std::pair<long long int, long long int> >::upper_bound(long long int&)'
  109 |       s.erase(s.begin(), s.upper_bound(v[i].first));
      |                          ~~~~~~~~~~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/set:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_set.h:871:9: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_upper_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::upper_bound(const _Kt&) [with _Key = std::pair<long long int, long long int>; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
  871 |         upper_bound(const _Kt& __x)
      |         ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:871:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype ((std::set<std::pair<long long int, long long int> >::iterator)(((std::set<std::pair<long long int, long long int> >*)this)->std::set<std::pair<long long int, long long int> >::_M_t.std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_upper_bound_tr(__x))) std::set<std::pair<long long int, long long int> >::upper_bound(const _Kt&) [with _Kt = long long int]':
a.cc:109:39:   required from here
  109 |       s.erase(s.begin(), s.upper_bound(v[i].first));
      |                          ~~~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:872:52: error: no matching function for call to 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_upper_bound_tr(const long long int&)'
  872 |         -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
      |                              ~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152:
/usr/include/c++/14/bits/stl_tree.h:1347:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_upper_bound_tr(const _Kt&) [with _Req = _Kt; _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
 1347 |         _M_upper_bound_tr(const _Kt& __k)
      |         ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1347:9: note:   template argument deduction/substitution failed:
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: In substitution of 'template<class _Func, class _SfinaeType> using std::__has_is_transparent_t = typename std::__has_is_transparent<_Func, _SfinaeType>::type [with _Func = std::less<std::pair<long long int, long long int> >; _SfinaeType = long long int]':
/usr/include/c++/14/bits/stl_tree.h:1345:9:   required by substitution of 'template<class _Kt> decltype ((std::set<std::pair<long long int, long long int> >::iterator)(((std::set<std::pair<long long int, long long int> >*)this)->std::set<std::pair<long long int, long long int> >::_M_t.std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_upper_bound_tr(__x))) std::set<std::pair<long long int, long long int> >::upper_bound(const _Kt&) [with _Kt = long long int]'
 1345 |                typename _Req = __has_is_transparent_t<_Compare, _Kt>>
      |                ^~~~~~~~
a.cc:109:39:   required from here
  109 |       s.erase(s.begin(), s.upper_bound(v[i].first));
      |                          ~~~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:1427:11: error: no type named 'type' in 'struct std::__has_is_transparent<std::less<std::pair<long long int, long long int> >, long long int, void>'
 1427 |     using __has_is_transparent_t
      |           ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype ((std::set<std::pair<long long int, long long int> >::iterator)(((std::set<std::pair<long long int, long long int> >*)this)->std::set<std::pair<long long int, long long int> >::_M_t.std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_upper_bound_tr(__x))) std::set<std::pair<long long int, long long int> >::upper_bound(const _Kt&) [with _Kt = long long int]':
a.cc:109:39:   required from here
  109 |       s.erase(s.begin(), s.upper_bound(v[i].first));
      |                          ~~~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1356:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_upper_bound_tr(const _Kt&) const [with _Req = _Kt; _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
 1356 |         _M_upper_bound_tr(const _Kt& __k) const
      |         ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1356:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h:877:9: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_upper_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::upper_bound(const _Kt&) const [with _Key = std::pair<long long int, long long int>; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
  877 |         upper_bound(const _Kt& __x) const
      |         ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:877:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype ((std::set<std::pair<long long int, long long int> >::iterator)(((const std::set<std::pair<long long int, long long int> >*)this)->std::set<std::pair<long long int, long long int> >::_M_t.std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_upper_bound_tr(__x))) std::set<std::pair<long long int, long long int> >::upper_bound(const _Kt&) const [with _Kt = long long int]':
a.cc:109:39:   required from here
  109 |       s.erase(s.begin(), s.upper_bound(v[i].first));
      |                          ~~~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:878:52: error: no matching function for call to 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_upper_bound_tr(const long long int&) const'
  878 |         -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
      |                              ~~~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:1347:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_upper_bound_tr(const _Kt&) [with _Req = _Kt; _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
 1347 |         _M_upper_bound_tr(const _Kt& __k)
      |         ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1347:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h:1356:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_upper_bound_tr(const _Kt&) const [with _Req = _Kt; _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
 1356 |         _M_upper_bound_tr(const _Kt& __k) const
      |         ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1356:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h:861:7: note: candidate: 'std::set<_Key,