Logical Moos
Time limit2sMemory limit1024 MB
Given a boolean and/or statement, each query asks whether replacing keywords l through r with one true or false can make the whole statement equal a target value.
- Level
Medium7 of 10
- Topics
- Segment tree, String, Implementation
- Solved
- No attempts yet
Problem
Farmer John has a boolean statement that is keywords long (, is odd). Only true or false appear in odd positions, while only and and or appear in even positions.
A phrase of the form x OPERATOR y, where and are each true or false and OPERATOR is and or or, evaluates as follows:
x and yis true if both and are true, and false otherwise.x or yis true if either or is true, and false otherwise.
When FJ evaluates the statement, he follows the precedence rules of Moo Language, which match C++: and takes priority over or. Repeat the following step until the statement consists of only one keyword.
- If the statement contains an
and, choose any of them and replace the phrase surrounding it with its evaluation. - Otherwise, the statement contains an
or. Choose any of them and replace the phrase surrounding it with its evaluation.
If several phrases can be evaluated in a given step, the choice does not matter. The statement always evaluates to the same value.
FJ receives queries (). In each query, he gives two odd integers and () and deletes the segment from keyword to keyword inclusive. He wants to replace the deleted segment with a single true or false so that the whole statement evaluates to a given value. Determine whether this is possible.
Input
The first line contains and .
The next line contains strings, which form a valid boolean statement.
Each of the following lines contains two integers and and a string true or false, the value the whole statement should have after the replacement.
Output
Output a string of length . The -th character is Y if the -th query is possible, and N otherwise.