问题 J: COW Operations 奶牛操作

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:28 通过:12

题目描述

Bessie 找到了一个长度不超过 2e, 且仅包含字符 'C''O' 'W' 的字符串 s。她想知道是否可以使用以下操作将该字符串变为单个字母 'C'(她最喜欢的字母):

1. 选择两个相邻相等的字母并将其删除。

2. 选择一个字母,将其替换为另外两个字母的任一排列。

求出这个字符串本身的答案对 Bessie 而言并不足够,所以她想要知道 s  Q1≤Q≤2×105)个子串的答案。

输入格式:

输入的第一行包含 s

第二行包含 Q

以下 Q 行每行包含两个整数 l  r1≤l≤r≤|s|,其中 |s| 表示 s 的长度)。

输出格式:

输出一个长为 Q 的字符串,如果第 i个子串可以被转变则第 i 个字符为 'Y',否则为 'N'

输入样例:

COW

6

1 1

1 2

1 3

2 2

2 3

3 3

输出样例:

YNNNYN

第一个询问的答案是「是」,因为 ss 的第一个字符已经等于 'C'

第五个询问的答案是「是」,因为 ss 的第二到第三个字符组成的子串 OW 可以通过两步操作变为 'C'

   OW

-> CWW

-> C

这个样例字符串 COW 的其他子串均不能被转变为 'C'





Bessie finds a string ss of length at most 2⋅1052⋅105 containing only the three characters 'C', 'O', and 'W'. She wants to know if it's possible to turn this string into a single 'C' (her favorite letter) using the following operations:

1. Choose two adjacent equal letters and delete them.

2. Choose one letter and replace it with the other two letters in either order.

Finding the answer on the string itself isn't enough for Bessie, so she wants to know the answer for QQ (1≤Q≤2⋅1051≤Q≤2⋅105) substrings of ss.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains ss. The next line contains QQ.
The next QQ lines each contain two integers ll and rr (1≤l≤r≤|s|1≤l≤r≤|s|, where |s||s| denotes the length of ss).

OUTPUT FORMAT (print output to the terminal / stdout):

A string of length QQ, with the ii-th character being 'Y' if the ii-th substring can be reduced and 'N' otherwise.

SAMPLE INPUT:

COW
6
1 1
1 2
1 3
2 2
2 3
3 3

SAMPLE OUTPUT:

YNNNYN

The answer to the first query is yes because the first character of ss is already equal to 'C'.

The answer to the fifth query is yes because the substring OW from the second to the third character of ss can be converted into 'C' in two operations:

   OW
-> CWW
-> C

No other substring of this example string COW can be reduced to 'C'





Bessie 找到了一个长度不超过 2 \cdot 10^52⋅10 
5
  且仅包含字符 'C','O' 和 'W' 的字符串 ss。她想知道是否可以使用以下操作将该字符串变为单个字母 'C'(她最喜欢的字母):

选择两个相邻相等的字母并将其删除。

选择一个字母,将其替换为另外两个字母的任一排列。

求出这个字符串本身的答案对 Bessie 而言并不足够,所以她想要知道 ss 的 QQ(1\le Q\le 2\cdot 10^51≤Q≤2⋅10 
5
 )个子串的答案。

输入格式
输入的第一行包含 ss。

第二行包含 QQ。

以下 QQ 行每行包含两个整数 ll 和 rr(1\le l\le r\le |s|1≤l≤r≤∣s∣,其中 |s|∣s∣ 表示 ss 的长度)。

输出格式
输出一个长为 QQ 的字符串,如果第 ii 个子串可以被转变则第 ii 个字符为 'Y',否则为 'N'。

输入输出样例
输入 #1复制
COW
6
1 1
1 2
1 3
2 2
2 3
3 3
输出 #1复制
YNNNYN
说明/提示
【样例解释】

第一个询问的答案是「是」,因为 s 的第一个字符已经等于 'C'。

第五个询问的答案是「是」,因为 s 的第二到第三个字符组成的子串 OW 可以通过两步操作变为 'C':

   OW
-> CWW
-> C
这个样例字符串 COW 的其他子串均不能被转变为 'C'。

输入样例 复制

COW
6
1 1
1 2
1 3
2 2
2 3
3 3

输出样例 复制

YNNNYN