Language: C++

#include <bits/stdc++.h>

using namespace std;

int r,c;

int sd(pair<int,int> a){
    int x,y;
    tie(x,y) = a;
    if(x==0)
        return 0;
    if(y==c)
        return 1;
    if(x==r)
        return 2;
    if(y==0)
        return 3;
    return -1;
}

bool bcmp(const pair<pair<int,int>,int>& a, const pair<pair<int,int>,int>& b){
    if(sd(a.first)!=sd(b.first))
        return sd(a.first)<sd(b.first);
    if(sd(a.first)<2)
        return a.first<b.first;
    return a.first>b.first;
}

int main(){
    scanf("%d%d",&r,&c);
    int n;
    scanf("%d",&n);
    vector<pair<pair<int,int>,int>> xvec;
    for(int i = 0; i<n; i++){
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        if(sd({x1,y1})!=-1&&sd({x2,y2})!=-1){
            xvec.push_back({{x1,y1},i});
            xvec.push_back({{x2,y2},i});
        }
    }
    sort(xvec.begin(),xvec.end(),bcmp);
    int xsz = xvec.size();
    for(int i = 0; i<xsz; i++)
        xvec.push_back(xvec[i]);
    xsz+=xsz;
    stack<int> ist;
    vector<int> xc(n,0);
    bool failed = false;
    for(int i = 0;i<xsz; i++){
        if(!ist.empty()&&ist.top()==xvec[i].second){
            xc[xvec[i].second]--;
            ist.pop();
        }else if(!xc[xvec[i].second]){
            xc[xvec[i].second]++;
            ist.push(xvec[i].second);
        }else{
            failed = true;
            break;
        }
    }
    if(failed)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:9: error: no matching function for call to 'sort(std::vector<std::pair<std::pair<int, int>, int> >::iterator, std::vector<std::pair<std::pair<int, int>, int> >::iterator, <unresolved overloaded function type>)'
   42 |     sort(xvec.begin(),xvec.end(),bcmp);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   template argument deduction/substitution failed:
a.cc:42:9: note:   couldn't deduce template parameter '_Compare'
   42 |     sort(xvec.begin(),xvec.end(),bcmp);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 3 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15:
/usr/include/c++/14/pstl/execution_defs.h: In substitution of 'template<class _ExecPolicy, class _Tp> using __pstl::__internal::__enable_if_execution_policy = typename std::enable_if<__pstl::execution::v1::is_execution_policy<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value, _Tp>::type [with _ExecPolicy = __gnu_cxx::__normal_iterator<std::pair<std::pair<int, int>, int>*, std::vector<std::pair<std::pair<int, int>, int> > >; _Tp = void]':
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1:   required by substitution of 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator) [with _ExecutionPolicy = __gnu_cxx::__normal_iterator<std::pair<std::pair<int, int>, int>*, std::vector<std::pair<std::pair<int, int>, int> > >; _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<std::pair<int, int>, int>*, std::vector<std::pair<std::pair<int, int>, int> > >]'
a.cc:42:9:   required from here
   42 |     sort(xvec.begin(),xvec.end(),bcmp);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/execution_defs.h:82:7: error: no type named 'type' in 'struct std::enable_if<false, void>'
   82 | using __enable_if_execution_policy =
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~