結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 23:28:08 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,238 bytes |
| 記録 | |
| コンパイル時間 | 440 ms |
| コンパイル使用メモリ | 85,760 KB |
| 実行使用メモリ | 175,500 KB |
| 最終ジャッジ日時 | 2026-04-17 23:29:20 |
| 合計ジャッジ時間 | 64,039 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 WA * 18 TLE * 8 |
ソースコード
import typing
class FenwickTree:
'''Reference: https://en.wikipedia.org/wiki/Fenwick_tree'''
def __init__(self, n: int = 0) -> None:
self._n = n
self.data = [0] * n
def add(self, p: int, x: typing.Any) -> None:
assert 0 <= p < self._n
p += 1
while p <= self._n:
self.data[p - 1] += x
p += p & -p
def sum(self, left: int, right: int) -> typing.Any:
assert 0 <= left <= right <= self._n
return self._sum(right) - self._sum(left)
def _sum(self, r: int) -> typing.Any:
s = 0
while r > 0:
s += self.data[r - 1]
r -= r & -r
return s
q=int(input())
p=k1=k2=0
ng=FenwickTree(q+1)
t=[]
for _ in range(q):
k,*c=input().split()
if k=='1':
c=c[0]
t+=c,
p+=1
if c=='(':
k1+=1
if c=='|':
k2+=1
if ng.sum(p,p+1)==0:
if k1<-(-p//3) or k2<-(-(p-1)//3)or k2>k1:
ng.add(p,1)
else:
p-=1
c=t.pop()
if c=='(':
k1-=1
if c=='|':
k2-=1
if ng.sum(p+1,p+2):
ng.add(p+1,-1)
if k1==k2==p-(k1+k2) and ng.sum(0,p+1)<1:
print('Yes')
else:
print('No')
# print([ng.sum(i,i+1)for i in range(p+5)],''.join(t))