結果
問題 | No.833 かっこいい電車 |
ユーザー |
|
提出日時 | 2022-12-02 18:43:47 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,371 bytes |
コンパイル時間 | 389 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 29,148 KB |
最終ジャッジ日時 | 2024-10-09 20:09:21 |
合計ジャッジ時間 | 6,468 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 3 WA * 5 TLE * 1 -- * 21 |
ソースコード
from bisect import bisect_left, insort_left from itertools import accumulate def main(): N, Q = map(int, input().split()) A = list(map(int, input().split())) disconnections = [idx for idx in range(N-1)] partial_sum = list(accumulate(A)) for _ in range(Q): query_type, x = map(int, input().split()) x -= 1 # 0-index match query_type: case 1: try: disconnections.remove(x) except ValueError: pass case 2: if x not in disconnections: insort_left(disconnections, x) case 3: partial_sum[x:] = list(map(lambda num: num+1, partial_sum[x:])) case 4: if not disconnections: print(partial_sum[-1]) continue range_idx = bisect_left(disconnections, x) if range_idx == len(disconnections): print(partial_sum[-1] - partial_sum[disconnections[-1]]) continue if range_idx == 0: print(partial_sum[0]) continue print(partial_sum[disconnections[range_idx]] - partial_sum[disconnections[range_idx-1]]) if __name__ == "__main__": main()