#63755. [ USACO 2022 Open Silver]COW Operation

[ USACO 2022 Open Silver]COW Operation

暂无测试数据。

英文题面

Bessie finds a string $s$ of length at most $2 \cdot 10^5$ 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 $Q$ ($1\le Q\le 2\cdot 10^5$) substrings of $s$.

译文

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

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

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

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

输入格式

The first line contains $s$.

The next line contains $Q$.

The next $Q$ lines each contain two integers $l$ and $r$ ($1\le l\le r\le |s|$, where $|s|$ denotes the length of $s$).

输入的第一行包含 $s$。

第二行包含 $Q$。

以下 $Q$ 行每行包含两个整数 $l$ 和 $r$($1\le l\le r\le |s|$,其中 $|s|$ 表示 $s$ 的长度)。

输出格式

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

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

数据范围

Test cases 2-4 satisfy $|s|\le 5000$ and $Q\le 5000$.Test cases 5-11 satisfy no additional constraints.

测试点 2-4 满足 $|s|\le 5000$ 以及 $Q\le 5000$。测试点 5-11 没有额外限制。

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