AT D求数据
  • 板块学术版
  • 楼主x1489631649
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/12/28 21:42
  • 上次更新2024/12/29 10:29:53
查看原帖
AT D求数据
780505
x1489631649楼主2024/12/28 21:42
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
	int x,y;
	string str;
}f[200005];
bool cmp(node x,node y)
{
	if(x.x!=y.x)
		return x.x<y.x;
	else return x.y<y.y;
}
bool cmp2(node x,node y)
{
	if(x.y!=y.y)
		return x.y<y.y;
	else return x.x<y.x;
}
signed main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>f[i].x>>f[i].y>>f[i].str;
	sort(f+1,f+m+1,cmp);
	int flag=0,flag1=0,flag2=n+1,p=0;
	for(int i=1;i<=m;i++)
	{
		if(f[i].y>flag2&&f[i].str=="B")
		{
			cout<<"No";
			return 0;
		}
		if(f[i].x==flag)
		{
			if(flag1==0)
			{
				if(f[i].str=="W")
					flag1=1;
				else p=f[i].y;
			}
			else {
				if(f[i].str=="B")
				{
					cout<<"No";
					return 0;
				}
			}
		}
		else {
			p=f[i].y;
			flag2=min(p,flag2);
			p=0;
			flag=f[i].x;
			if(f[i].str=="W")
				flag1=1;
			else flag1=0;
		}
	}
	sort(f+1,f+m+1,cmp2);
	flag=0,flag1=0,flag2=n+1,p=0;
	for(int i=1;i<=m;i++)
	{
		if(f[i].x>flag2&&f[i].str=="B")
		{
			cout<<"No";
			return 0;
		}
		if(f[i].y==flag)
		{
			if(flag1==0)
			{
				if(f[i].str=="W")
					flag1=1;
				else p=f[i].x;
			}
			else {
				if(f[i].str=="B")
				{
					cout<<"No";
					return 0;
				}
			}
		}
		else {
			p=f[i].x;
			flag2=min(p,flag2);
			p=0;
			flag=f[i].y;
			if(f[i].str=="W")
				flag1=1;
			else flag1=0;
		}
	}
	cout<<"Yes";
}
2024/12/28 21:42
加载中...