Under construction

Still being built. Things may change

Logical Moos

Time limit2sMemory limit1024 MB

Summary
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 NN keywords long (1≤N<2⋅1051 \leq N < 2 \cdot 10^5, NN 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 xx and yy are each true or false and OPERATOR is and or or, evaluates as follows:

  • x and y is true if both xx and yy are true, and false otherwise.
  • x or y is true if either xx or yy 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.

  1. If the statement contains an and, choose any of them and replace the phrase surrounding it with its evaluation.
  2. 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 QQ queries (1≤Q≤2⋅1051 \leq Q \leq 2 \cdot 10^5). In each query, he gives two odd integers ll and rr (1≤l≤r≤N1 \leq l \leq r \leq N) and deletes the segment from keyword ll to keyword rr 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 NN and QQ.

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

Each of the following QQ lines contains two integers ll and rr and a string true or false, the value the whole statement should have after the replacement.

Output

Output a string of length QQ. The ii-th character is Y if the ii-th query is possible, and N otherwise.

Examples2

  1. Example 1

    Input
    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
    
    Expected output
    NYYYNYY
    
  2. Example 2

    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
    
    Expected output
    YNYY