結果

問題 No.1000 Point Add and Array Add
ユーザー 👑 tamatotamato
提出日時 2020-02-28 21:38:15
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 502 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 153,116 KB
最終ジャッジ日時 2023-08-03 19:49:16
合計ジャッジ時間 8,121 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,268 KB
testcase_01 AC 76 ms
71,460 KB
testcase_02 AC 78 ms
71,456 KB
testcase_03 AC 76 ms
71,548 KB
testcase_04 AC 78 ms
71,400 KB
testcase_05 AC 78 ms
71,276 KB
testcase_06 AC 77 ms
71,320 KB
testcase_07 AC 78 ms
71,324 KB
testcase_08 AC 77 ms
71,280 KB
testcase_09 AC 77 ms
71,236 KB
testcase_10 AC 77 ms
71,276 KB
testcase_11 AC 76 ms
71,276 KB
testcase_12 AC 109 ms
76,600 KB
testcase_13 AC 94 ms
76,776 KB
testcase_14 AC 111 ms
78,396 KB
testcase_15 AC 106 ms
77,528 KB
testcase_16 AC 332 ms
131,276 KB
testcase_17 AC 325 ms
121,844 KB
testcase_18 AC 436 ms
152,816 KB
testcase_19 AC 502 ms
152,904 KB
testcase_20 AC 426 ms
150,004 KB
testcase_21 AC 394 ms
153,116 KB
testcase_22 AC 412 ms
152,872 KB
testcase_23 AC 407 ms
152,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

    N, Q = map(int, input().split())
    A = list(map(int, input().split()))
    query = [None] * Q
    for i in range(Q):
        query[Q-i-1] = tuple(input().split())

    bit = Bit(N+3)
    ans = [0] * (N+1)
    for flg, x, y in query:
        x = int(x)
        y = int(y)
        if flg == 'B':
            bit.add(x, 1)
            bit.add(y+1, -1)
        else:
            ans[x] += y * bit.sum(x)
    for x in range(1, N+1):
        ans[x] += A[x-1] * bit.sum(x)
    print(*ans[1:])




if __name__ == '__main__':
    main()
0