Logo
(追記) (追記ここまで)

31772번 - Logical Moos 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB171644642.593%

문제

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

A phrase of the form $x\text{ OPERATOR }y,ドル where $x$ and $y$ are either true or false, and $\text{OPERATOR}$ is and or or, evaluates as follows:

  • $x$ and $y$: This evaluates to true if both $x$ and $y$ are true, and false otherwise.
  • $x$ or $y$: This evaluates to true if either $x$ or $y$ 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 $Q$ $(1 \leq Q \leq 2 \cdot 10^5)$ queries. In each query, he gives you two integers $l$ and $r$ (1ドル \leq l \leq r \leq N,ドル $l$ and $r$ are both odd), and deletes the segment from keyword $l$ to keyword $r$ 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 $N$ and $Q$.

The next line contains $N$ strings, a valid boolean statement.

The following $Q$ lines contain two integers $l$ and $r,ドル and a string true or false, denoting whether he wants the whole statement to evaluate to true or false.

출력

Output a string of length $Q,ドル where the $i$'th character is Y if the $i$'th query is possible, otherwise N.

제한

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

예제 출력 1

NYYYNYY

Let's analyze the first query:

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

true and true or true

We evaluate the and keyword from at position 2ドル$ and obtain

true or true

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

true

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

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

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

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

예제 출력 2

YNYY

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2024 US Open Contest > Bronze 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /