Logical Moos

시간 제한2초메모리 제한1024 MB

요약
긴 and/or 불리언 식이 주어질 때, 홀수 위치에서 시작하고 끝나는 연속 구간을 지우고 그 자리에 true 또는 false 하나를 넣어 전체 식을 원하는 값으로 만들 수 있는지 묻는 질의에 답한다.
난이도

어려움10점 중 8점

유형
구현, 누적 합, 수학, 구간
정답자
아직 제출이 없습니다

문제

Farmer John has a boolean statement that is NN keywords long (1≤N<2⋅1051 \leq N < 2 \cdot 10^5, NN 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 yx\text{ OPERATOR }y, where xx and yy are either true or false, and OPERATOR\text{OPERATOR} is and or or, evaluates as follows:

  • xx and yy: This evaluates to true if both xx and yy are true, and false otherwise.
  • xx or yy: 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 takes priority over 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, 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.

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 (1≤Q≤2⋅105)(1 \leq Q \leq 2 \cdot 10^5) queries. In each query, he gives you two integers ll and rr (1≤l≤r≤N1 \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 or 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 or 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.

예제2

  1. 예제 1

    입력
    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
    
  2. 예제 2

    입력
    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