結果

問題 No.1802 Range Score Query for Bracket Sequence
ユーザー ああいいああいい
提出日時 2022-01-14 18:01:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 825 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 88,400 KB
最終ジャッジ日時 2024-04-30 01:42:59
合計ジャッジ時間 10,479 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 652 ms
86,604 KB
testcase_15 WA -
testcase_16 AC 41 ms
51,712 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 41 ms
51,840 KB
testcase_21 AC 41 ms
51,968 KB
testcase_22 AC 40 ms
51,712 KB
testcase_23 AC 41 ms
51,840 KB
testcase_24 AC 43 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Q = map(int,input().split())
S = input()
bit = [0] * N
def add(i,x):
    while i <= N-1:
        bit[i] += x
        i += i & -i
def getsum(i):
    ans = 0
    while i > 0:
        ans += bit[i]
        i -= i & -i
    return ans
l = list(S)
for i in range(N-1):
    if l[i] == '(' and l[i+1] == ')':
        add(i+1,1)
for _ in range(Q):
    t = list(map(int,input().split()))
    if t[0] == 2:
        print(getsum(t[2]-1)-getsum(t[1]-1))
    else:
        i = t[1]
        if l[i-1] == '(':
            if i < N and l[i] == ')':
                add(i,-1)
            if i >= 2 and l[i-2] == '(':
                add(i-1,1)
            l[i-1] = ')'
        else:
            if i >= 2 and l[i-2] == '(':
                add(i-1,-1)
            if i < N and l[i] == ')':
                add(i,1)
            l[i-1] == '('
0