結果
| 問題 | No.3652 Range Bracket Sequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-22 16:07:24 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,580 bytes |
| 記録 | |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 96,112 KB |
| 実行使用メモリ | 177,888 KB |
| 最終ジャッジ日時 | 2026-08-28 21:06:36 |
| 合計ジャッジ時間 | 31,410 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 10 WA * 47 |
ソースコード
def copy(n):return n.copy()if hasattr(n,"copy")else n
def rec_str(a):return"".join(["[",", ".join(rec_str(x)for x in a),"]"])if isinstance(a,list)else str(a)
class SegmentTree:
e=(0,0,0) #User's definition
def op(x,y): #User's definition
lr=min(x[2],y[0])
return(x[0]+y[0]-lr,x[1]+y[1]+lr,x[2]+y[2]-lr)
def __init__(self,x):
b=isinstance(x,int)
if b:self.N=x
else:self.N=len(x)
self.p=1
while self.N>self.p:self.p<<=1
if b:self.T=[copy(__class__.e)for i in R(self.p<<1)]
else:
self.T=[__class__.e]*(self.p<<1)
for i in R(0,self.N):self.T[self.p|i]=copy(x[i])
for j in R(self.p-1,0,-1):self.T[j]=__class__.op(self.T[j<<1],self.T[(j<<1)|1])
def copy(self):
a=__class__([])
a.N=self.N
a.p=self.p
a.T=copy(self.T)
return a
def Set(self,i,u):
assert 0<=i<self.N
j=self.p|i
self.T[j],j=u,j>>1
while j:self.T[j],j=__class__.op(self.T[j<<1],self.T[(j<<1)|1]),j>>1
def Get(self,i):
assert 0<=i<self.N
return self.IntervalProduct(i,i)
def IntervalProduct(self,l,r): #l,rは始端,終端
l,r=max(0,l),min(r,self.N-1)
assert l-1<=r
l|=self.p
r+=self.p+1
a,b=copy(__class__.e),copy(__class__.e)
while l<r:
if l&1:a,l=__class__.op(a,self.T[l]),l+1
if r&1:b,r=__class__.op(self.T[r-1],b),r-1
l,r=l>>1,r>>1
return __class__.op(a,b)
R=range
I=input
J=lambda:map(int,I().split())
N,Q=J()
S=[c for c in I()]
def T(c):return(c==')',0,c=='(')
X=SegmentTree([T(c)for c in S])
for q in R(Q):
t,l,r=J()
if t<2:
c="()"[t-1]
if S[l-1]!=c:
S[l-1]=c
X.Set(l-1,T(c))
else:print(X.IntervalProduct(l-1,r-1)[1]*2)