結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー tyuyu_62
提出日時 2026-04-18 09:55:21
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 2,047 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 236 ms
コンパイル使用メモリ 85,760 KB
実行使用メモリ 223,232 KB
最終ジャッジ日時 2026-04-18 09:55:44
合計ジャッジ時間 18,620 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# snippet: templete_
# Last Modified: 2026-02-13

from collections import deque, defaultdict
from itertools import permutations, product
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop
from random import randint, shuffle
from time import perf_counter as pc
def II(): return int(input())
def LI(): return list(map(int,input().split()))
def LI_1(): return [int(x) - 1 for x in input().split()]
def SI(): return input()
def LS(): return list(input().split())
mod = 998244353
inf = 1001001001001001001

import sys
sys.setrecursionlimit(10 ** 6)
input = lambda: sys.stdin.readline().rstrip()
_buf = []
def print(*a, **k): _buf.append(" ".join(map(str, a)))


def solve():
    Q = II()
    stack = []
    A = [0, 1, -1] # sum, is_ok, ban
    B = [0, 1, -1]
    for i in range(Q):
        q = LS()
        if q[0] == "1":
            c = q[1]
            if c == "(":
                A[0] += 1
            elif c == "|":
                A[0] -= 1
                if A[0] < 0 and A[1]:
                    A[1] = 0
                    A[2] = len(stack)
                B[0] += 1
            else:
                B[0] -= 1
                if B[0] < 0 and B[1]:
                    B[1] = 0
                    B[2] = len(stack)
            stack.append(c)
        else:
            c = stack.pop()
            if c == "(":
                A[0] -= 1
            elif c == "|":
                A[0] += 1
                if A[2] == len(stack):
                    assert A[0] == A[1] == 0
                    A[1] = 1
                    A[2] = -1
                B[0] -= 1
            else:
                B[0] += 1
                if B[2] == len(stack):
                    assert B[0] == B[1] == 0
                    B[1] = 1
                    B[2] = -1
        if A[0] == 0 and A[1] and B[0] == 0 and B[1]:
            print("Yes")
        else:
            print("No")
    return

if __name__ == "__main__":
    T = 1
    # T = II()
    for _ in range(T):
        solve()
    sys.stdout.write("\n".join(_buf) + "\n")
0