問題一覧 > 通常問題

No.3503 Brackets Stack Query 2

レベル : / AI推定難易度 : 1250 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 101
作問者 : n_bitand_n_per_3 / テスター : Naru820 Nzt3 irinoirino Solalyth
お気に入りにしたユーザー ProblemId : 13228 / 自分の提出
問題文最終更新日: 2026-04-30 02:23:34
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
CPCTF 2026: PPC (順位表) の他の問題:

Problem Statement

A string $T$ is called a good barred bracket sequence if $T$ satisfies the following condition.

  • $T$ can be turned into the empty string by repeating the following operation 0 or more times.
    • Choose an occurrence of (|) as a (contiguous) substring and remove it.

For example, (|), ((|)|(|)), and the empty string are good barred bracket sequences, but )|( and )||()) are not.

There is a string $S$. $S$ is initially the empty string. Process the $Q$ queries described below in the given order. Then, immediately after each query, determine whether $S$ is a good barred bracket sequence. There are 2 types of queries.

  • 1 c: A character $c$ is given. $c$ is (, |, or ). Append $c$ to the end of $S$.
  • 2: Delete the last character of $S$. Here, it is guaranteed that $S$ is not the empty string.

Constraints

  • $1≤Q≤8 \times 10^5$
  • In a query of the 1st type, $c$ is (, |, or )
  • $S$ is not empty when a query of the 2nd type is given

Input

The input is given from Standard Input in the following format.
$Q$
$\text{query}_1$
...
$\text{query}_Q$

Here, $\text{query}_i$ represents the $i$-th query and is given in one of the following formats.

$1 ~ c$
$2$

Output

Print $Q$ lines. On the $i$-th line, print Yes if $S$ immediately after processing the $i$-th query is a good barred bracket sequence, and No otherwise.

Sample

Sample 1
Input
5
1 (
1 |
1 )
2
1 |
Output
No
No
Yes
No
No

After processing the 1st query, S is (. This is not a good barred bracket sequence.

After processing the 2nd query, S is (|. This is not a good barred bracket sequence.

After processing the 3rd query, S is (|). This is a good barred bracket sequence.

After processing the 4th query, S is (|. This is not a good barred bracket sequence.

After processing the 5th query, S is (||. This is not a good barred bracket sequence.

Sample 2
Input
2
1 (
1 )
Output
No
No

An ordinary bracket sequence () does not fit the definition used here.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。