比赛 2025暑期集训第6场 评测结果 AAAAAAAAAA
题目名称 Cow Operations 最终得分 100
用户昵称 xxz 运行时间 0.423 s
代码语言 C++ 内存使用 6.53 MiB
提交时间 2025-07-12 08:43:55
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s,ans;
int q,l,r,nc[223456],nq[223456],nw[223456],cntc,cntw,cntq;
void read(int &x) {bool neg = false;x = 0;char ch = 0;while (ch < '0' || ch > '9') {if (ch == '-') neg = true;ch = getchar();}if (neg) {while (ch >= '0' && ch <= '9') {x = x * 10 + ('0' - ch);ch = getchar();}} else {while (ch >= '0' && ch <= '9') {x = x * 10 + (ch - '0');ch = getchar();}}return;}
signed main(){
	freopen("operation.in","r",stdin);freopen("operation.out","w",stdout);
	cin>>s;
	s=' '+s;
	for(int i=1;i<=s.size();i++){
		if(s[i]=='C'){
			nc[i]=nc[i-1]+1;
			nq[i]=nq[i-1];
			nw[i]=nw[i-1];
		}else if(s[i]=='W'){
			nw[i]=nw[i-1]+1;
			nc[i]=nc[i-1];
			nq[i]=nq[i-1];
		}else{
			nq[i]=nq[i-1]+1;
			nc[i]=nc[i-1];
			nw[i]=nw[i-1];
		}
	}
	read(q);
	while(q--){
		read(l);read(r);
		cntc=nc[r]-nc[l-1];
		cntw=nw[r]-nw[l-1];
		cntq=nq[r]-nq[l-1];
		if(cntw%2==cntq%2&&cntc%2!=cntw%2){
			ans+='Y';
		}else {
			ans+='N';
		}
	}
	cout<<ans;
	return 0;
}