結果

問題 No.1000 Point Add and Array Add
ユーザー wattaiheiwattaihei
提出日時 2020-02-28 21:49:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 481 ms / 2,000 ms
コード長 1,159 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 155,068 KB
最終ジャッジ日時 2023-08-03 20:02:12
合計ジャッジ時間 7,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,304 KB
testcase_01 AC 74 ms
71,396 KB
testcase_02 AC 73 ms
71,416 KB
testcase_03 AC 74 ms
71,432 KB
testcase_04 AC 74 ms
71,424 KB
testcase_05 AC 73 ms
71,304 KB
testcase_06 AC 75 ms
71,428 KB
testcase_07 AC 74 ms
71,380 KB
testcase_08 AC 73 ms
71,260 KB
testcase_09 AC 74 ms
71,252 KB
testcase_10 AC 75 ms
71,228 KB
testcase_11 AC 74 ms
71,088 KB
testcase_12 AC 107 ms
77,944 KB
testcase_13 AC 101 ms
76,992 KB
testcase_14 AC 117 ms
78,316 KB
testcase_15 AC 106 ms
77,792 KB
testcase_16 AC 353 ms
124,584 KB
testcase_17 AC 320 ms
112,096 KB
testcase_18 AC 461 ms
144,176 KB
testcase_19 AC 457 ms
144,564 KB
testcase_20 AC 445 ms
150,708 KB
testcase_21 AC 358 ms
128,864 KB
testcase_22 AC 481 ms
155,068 KB
testcase_23 AC 393 ms
131,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 足す時は0~iまで一律に足し、返すのはi番目の値
class imosBIT():
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(self.N+1)]
    
    def __str__(self):
        ret = []
        for i in range(1, self.N+1):
            ret.append(self.__getitem__(i))
        return "[" + ", ".join([str(a) for a in ret]) + "]"

    def __getitem__(self, i):
        s = 0
        while i <= self.N:
            s += self.bit[i]
            i += i & -i
        return s

    def add(self, i, x):
        while i > 0:
            self.bit[i] += x
            i -= i & -i


import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
A = list(map(int, input().split()))
Query = []
for _ in range(Q):
    a, b, c = map(str, input().split())
    Query.append((a=="A", int(b), int(c)))

bit = imosBIT(N)

P = []
for isA, x, y in Query:
    if isA:
        p = bit[x]
        # x番目は今pで、yをたす
        P.append((x, p, y))
    else:
        bit.add(y, 1)
        bit.add(x-1, -1)

ans = []
for i, a in enumerate(A):
    ans.append(bit[i+1]*a)

for x, p, y in P:
    ans[x-1] += y*(bit[x]-p)

print(*ans)
0