样例输入 1
4 2 3
0 1 3 1
1 1 4 1
2 0 2 2
样例输出 1
YES
样例输入 2
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
样例输出 2
NO
样例输入 3
5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1
样例输出 3
YES
样例输入 4
1 1 2
0 0 1 1
1 0 0 1
#include <bits/stdc++.h>
using namespace std;
int r,c,n,cnt;
struct node
{
int x,y,id,opt;
} a[200001];
bool operator < (node x,node y)
{
if (x.opt==y.opt)
{
if (x.opt==1)
return x.y<y.y;
if (x.opt==2)
return x.x<y.x;
if (x.opt==3)
return x.y>y.y;
if (x.opt==4)
return x.x>y.x;
}
return x.opt<y.opt;
}
bool check (int x,int y)
{
return x==0||x==r||y==0||y==c;
}
int get (int x,int y)
{
if (x==0)
return 1;
if (y==c)
return 2;
if (x==r)
return 3;
if (y==0)
return 4;
}
stack<int>s;
int main()
{
scanf("%d%d%d",&r,&c,&n);
for(int i=1;i<=n;i++)
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if (check(x1,y1)&&check(x2,y2))
{
a[++cnt].x=x1;
a[cnt].y=y1;
a[cnt].id=i;
a[cnt].opt=get(x1,y1);
a[++cnt].x=x2;
a[cnt].y=y2;
a[cnt].id=i;
a[cnt].opt=get(x2,y2);
}
}
sort(a+1,a+1+cnt);
for (int i=1;i<=cnt;i++)
{
if (!s.empty()&&a[i].id==s.top())
s.pop();
else
s.push(a[i].id);
}
if (s.empty())
puts("YES");
else
puts("NO");
}