結果
| 問題 |
No.1802 Range Score Query for Bracket Sequence
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2022-01-07 23:29:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,879 bytes |
| コンパイル時間 | 340 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 103,128 KB |
| 最終ジャッジ日時 | 2024-11-14 09:16:41 |
| 合計ジャッジ時間 | 6,728 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 6 WA * 18 |
ソースコード
import sys
from sys import stdin
#0-indexed , 半開区間[a,b)
#calc変更で演算変更
class SegTree:
def __init__(self,N,first):
self.NO = 2**(N-1).bit_length()
self.First = first
self.data = [first] * (2*self.NO)
def calc(self,l,r):
return l+r
def update(self,ind,x):
ind += self.NO - 1
self.data[ind] = x
while ind >= 0:
ind = (ind - 1)//2
self.data[ind] = self.calc(self.data[2*ind+1],self.data[2*ind+2])
def query(self,l,r):
L = l + self.NO
R = r + self.NO
s = self.First
while L < R:
if R & 1:
R -= 1
s = self.calc(s , self.data[R-1])
if L & 1:
s = self.calc(s , self.data[L-1])
L += 1
L >>= 1
R >>= 1
return s
def get(self , ind):
ind += self.NO - 1
return self.data[ind]
N,Q = map(int,stdin.readline().split())
S = list(stdin.readline()[:-1])
ST = SegTree(N-1,0)
for i in range(N-1):
if S[i] == "(" and S[i+1] == ")":
ST.update(i,1)
ANS = []
for loop in range(Q):
query = stdin.readline()[:-1]
if query[0] == "1":
_,ind = map(int,query.split())
ind -= 1
if S[ind] == ")" and ind != 0 and ST.get(ind-1) == 1:
ST.update(i-1,0)
if S[ind] == "(" and ind != N-1 and ST.get(ind+1) == 1:
ST.update(i,0)
if S[ind] == "(":
S[ind] = ")"
else:
S[ind] = "("
if S[ind] == ")" and ind != 0 and S[ind-1] == "(":
ST.update(i-1,1)
if S[ind] == "(" and ind != N-1 and S[ind+1] == ")":
ST.update(i,1)
else:
_,l,r = map(int,query.split())
l -= 1
r -= 1
ANS.append(ST.query(l,r))
print ("\n".join(map(str,ANS)))
SPD_9X2