#P10274. [USACO24OPEN] Logical Moos B

[USACO24OPEN] Logical Moos B

题目描述

Farmer John has a boolean statement that is NN keywords long (1N<21051 \leq N < 2 \cdot 10^5, NN odd). Only true\texttt{true} or false\texttt{false} appear in odd positions, while only and\texttt{and} and or\texttt{or} appear in even positions.

A phrase of the form x OPERATOR yx\text{ OPERATOR }y, where xx and yy are either true\texttt{true} or false\texttt{false}, and OPERATOR\text{OPERATOR} is and\texttt{and} or or\texttt{or}, evaluates as follows:

  • x and yx\texttt{ and }y: This evaluates to true if both xx and yy are true, and false otherwise.
  • x or yx\texttt{ or }y: This evaluates to true if either xx or yy is true, and false otherwise.

When evaluating the statement, FJ has to take the order of precedence in Moo Language into account. Similar to C++, and\texttt{and} takes priority over or\texttt{or}. More specifically, to evaluate the statement, repeat the following step until the statement consists of only one keyword.

  1. If the statement contains an and\texttt{and}, choose any of them and replace the phrase surrounding it with its evaluation.
  2. Otherwise, the statement contains an or\texttt{or}. Choose any of them and replace the phrase surrounding it with its evaluation.

It may be proven that if multiple phrases can be evaluated during a given step, it does not matter which one is chosen; the statement will always evaluate to the same value.

FJ has QQ (1Q2105)(1 \leq Q \leq 2 \cdot 10^5) queries. In each query, he gives you two integers ll and rr (1lrN1 \leq l \leq r \leq N, ll and rr are both odd), and deletes the segment from keyword ll to keyword rr inclusive. In turn, he wishes to replace the segment he just deleted with just one simple true\texttt{true} or false\texttt{false} so that the whole statement evaluates to a certain boolean value. Help FJ determine if it's possible!

输入格式

The first line contains NN and QQ.

The next line contains NN strings, a valid boolean statement.

The following QQ lines contain two integers ll and rr, and a string true\texttt{true} or false\texttt{false}, denoting whether he wants the whole statement to evaluate to true or false.

输出格式

Output a string of length QQ, where the ii'th character is Y if the ii'th query is possible, otherwise N.

5 7
false and true or true
1 1 false
1 3 true
1 5 false
3 3 true
3 3 false
5 5 false
5 5 true
NYYYNYY
13 4
false or true and false and false and true or true and false
1 5 false
3 11 true
3 11 false
13 13 true
YNYY

提示

For Sample 1:

Let's analyze the first query:

If we were to replace delete the segment [1,1][1, 1] and replace it with true\texttt{true}, then the whole statement becomes:

true and true or true

We evaluate the and\texttt{and} keyword from at position 22 and obtain

true or true

Since we have no and\texttt{and} keywords left, we have to evaluate the or\texttt{or} keyword. After evaluation, all that is left is

true

It can be shown that if we were to replace the segment with false\texttt{false}, the statement will still evaluate to true\texttt{true}, so we output N since the statement cannot possibly evaluate to false\texttt{false}.

For the second query, we can replace the segment [1,3][1, 3] with true\texttt{true} and the whole statement will evaluate to true\texttt{true}, so we output Y.

For the third query, since [1,5][1, 5] is the whole statement, we can replace it with anything, so we output Y.

SCORING:

  • Inputs 3-5: N,Q102N,Q\le 10^2
  • Inputs 6-8: N,Q103N,Q\le 10^3
  • Inputs 9-26: No additional constraints.