結果
問題 | No.1802 Range Score Query for Bracket Sequence |
ユーザー |
![]() |
提出日時 | 2022-01-14 23:31:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 310 ms / 2,000 ms |
コード長 | 1,336 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 150,464 KB |
最終ジャッジ日時 | 2024-06-30 02:22:08 |
合計ジャッジ時間 | 6,473 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 24 |
ソースコード
from sys import stdinn, q = [int(x) for x in stdin.readline().rstrip().split()]s = stdin.readline().rstrip()indata = list(map(int, stdin.read().split()))bitree = [0 for i in range(n+1)]def btadd(ind,x):global bitreewhile ind <= n:bitree[ind] += xind += ind & (-ind)def btsum(ind):val = 0while ind > 0:val += bitree[ind]ind -= ind & (-ind)return valbracket = [0 for i in range(n)]if s[0] == ")":bracket[0] = 1for i in range(1,n):if s[i] == ")":bracket[i] = 1if bracket[i-1] == 0:btadd(i+1,1)offset = 0for i in range(q):a = indata[offset]if a == 1:x = indata[offset + 1] - 1offset += 2if bracket[x] == 0:if x < n-1:if bracket[x+1] == 1:btadd(x+2,-1)if x > 0:if bracket[x-1] == 0:btadd(x+1,1)else:if x < n-1:if bracket[x+1] == 1:btadd(x+2,1)if x > 0:if bracket[x-1] == 0:btadd(x+1,-1)bracket[x] = bracket[x] ^ 1else:l, r = indata[offset + 1], indata[offset + 2]offset += 3ans = btsum(r) - btsum(l)print("{}".format(ans))