結果
問題 |
No.1802 Range Score Query for Bracket Sequence
|
ユーザー |
![]() |
提出日時 | 2025-03-31 17:53:12 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 914 bytes |
コンパイル時間 | 219 ms |
コンパイル使用メモリ | 82,236 KB |
実行使用メモリ | 245,088 KB |
最終ジャッジ日時 | 2025-03-31 17:54:32 |
合計ジャッジ時間 | 4,687 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | TLE * 1 -- * 23 |
ソースコード
import sys def main(): input = sys.stdin.read().split() ptr = 0 N, Q = int(input[ptr]), int(input[ptr+1]) ptr +=2 S = list(input[ptr]) ptr +=1 for _ in range(Q): query = input[ptr] ptr +=1 if query == '1': i = int(input[ptr])-1 ptr +=1 S[i] = '(' if S[i] == ')' else ')' else: l = int(input[ptr])-1 r = int(input[ptr+1])-1 ptr +=2 stack = [] count =0 current_balance =0 for c in S[l:r+1]: if c == '(': current_balance +=1 else: current_balance -=1 if current_balance <0: current_balance =0 elif current_balance ==0: count +=1 print(count) if __name__ == '__main__': main()