#P8271. [USACO22OPEN] COW Operations S

[USACO22OPEN] COW Operations S

Problem Description

Bessie found a string ss of length at most 21052 \cdot 10^5 that contains only the characters 'C', 'O', and 'W'. She wants to know whether she can use the following operations to turn the string into a single letter 'C' (her favorite letter):

  1. Choose two adjacent equal letters and delete them.

  2. Choose one letter and replace it with any permutation of the other two letters.

Knowing the answer for the whole string alone is not enough for Bessie, so she wants to know the answers for QQ (1Q21051 \le Q \le 2 \cdot 10^5) substrings of ss.

Input Format

The first line contains ss.

The second line contains QQ.

The next QQ lines each contain two integers ll and rr (1lrs1 \le l \le r \le |s|), where s|s| is the length of ss.

Output Format

Output a string of length QQ. If the ii-th substring can be transformed, then the ii-th character should be 'Y', otherwise it should be 'N'.

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

Hint

[Sample Explanation]

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 formed by the second to third characters of ss, namely OW, can be turned into 'C' in two operations:

   OW
-> CWW
-> C

All other substrings of the sample string COW cannot be transformed into 'C'.

[Test Point Properties]

  • Test points 2-4 satisfy s5000|s| \le 5000 and Q5000Q \le 5000.
  • Test points 5-11 have no additional constraints.

Translated by ChatGPT 5