結果

問題 No.833 かっこいい電車
ユーザー ThetaTheta
提出日時 2022-12-02 18:43:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,371 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 27,848 KB
最終ジャッジ日時 2024-04-18 02:28:22
合計ジャッジ時間 6,123 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 678 ms
22,508 KB
testcase_01 WA -
testcase_02 AC 28 ms
10,880 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 28 ms
11,008 KB
testcase_07 WA -
testcase_08 AC 28 ms
10,880 KB
testcase_09 AC 29 ms
11,008 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0