2039: [USACO 2024 US Open Contest Bronze] Problem 1. Logical Moos
题目描述
Farmer John has a boolean statement that is keywords long (, odd). Only
or appear in odd positions, while only and appear in even positions.A phrase of the form , where and are either
or , and is or , evaluates as follows:- : This evaluates to true if both and are true, and false otherwise.
- : This evaluates to true if either or 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++,
takes priority over . More specifically, to evaluate the statement, repeat the following step until the statement consists of only one keyword.- If the statement contains an , choose any of them and replace the phrase surrounding it with its evaluation.
- Otherwise, the statement contains an . 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 queries. In each query, he gives you two integers and (, and are both odd), and deletes the segment from keyword to keyword inclusive. In turn, he wishes to replace the segment he just deleted with just one simple
or so that the whole statement evaluates to a certain boolean value. Help FJ determine if it's possible!输入
The next line contains strings, a valid boolean statement.
The following lines contain two integers and , and a string ng whether he wants the whole statement to evaluate to true or false.
or , denoti输出
样例输入
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
提示
Let's analyze the first query:
If we were to replace delete the segment and replace it with
, then the whole statement becomes:true and true or true
We evaluate the
keyword from at position and obtaintrue or true
Since we have no
keywords left, we have to evaluate the keyword. After evaluation, all that is left istrue
It can be shown that if we were to replace the segment with
, the statement will still evaluate to , so we output N since the statement cannot possibly evaluate to .For the second query, we can replace the segment with
and the whole statement will evaluate to , so we output Y.For the third query, since is the whole statement, we can replace it with anything, so we output Y.
SAMPLE INPUT:
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
SAMPLE OUTPUT:
YNYY
SCORING:
- Inputs 3-5:
- Inputs 6-8:
- Inputs 9-26: No additional constraints.