結果

問題 No.1000 Point Add and Array Add
ユーザー AEnAEn
提出日時 2022-12-31 14:59:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 142,200 KB
最終ジャッジ日時 2023-08-17 15:28:16
合計ジャッジ時間 9,210 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,400 KB
testcase_01 AC 68 ms
71,384 KB
testcase_02 AC 68 ms
71,428 KB
testcase_03 AC 67 ms
71,608 KB
testcase_04 AC 69 ms
71,324 KB
testcase_05 AC 69 ms
71,068 KB
testcase_06 AC 70 ms
71,424 KB
testcase_07 AC 70 ms
71,588 KB
testcase_08 AC 68 ms
71,448 KB
testcase_09 AC 68 ms
71,492 KB
testcase_10 AC 69 ms
71,484 KB
testcase_11 AC 67 ms
71,404 KB
testcase_12 AC 113 ms
78,344 KB
testcase_13 AC 111 ms
78,012 KB
testcase_14 AC 118 ms
78,488 KB
testcase_15 AC 117 ms
78,004 KB
testcase_16 AC 367 ms
124,144 KB
testcase_17 AC 351 ms
114,156 KB
testcase_18 AC 486 ms
142,148 KB
testcase_19 AC 480 ms
142,200 KB
testcase_20 AC 441 ms
139,088 KB
testcase_21 AC 469 ms
142,156 KB
testcase_22 AC 471 ms
142,104 KB
testcase_23 AC 484 ms
142,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Binary_Indexed_Tree:
    def __init__(self, n) -> None:
        self._n = n
        self.data = [0] * (n+1)
        self.depth = n.bit_length()

    def add(self, p, x) -> None:
        """任意の要素ai←ai+xを行う O(logn)"""
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p-1] += x
            p += p & (-p)
    
    def sum(self, l, r) -> int:
        """区間[l,r)で計算"""
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)
    
    def _sum(self, d) -> int:
        sm = 0
        while d > 0:
            sm += self.data[d-1]
            d -= d & (-d)
        return sm

N, Q = map(int, input().split())
A = list(map(int, input().split()))
q = [list(map(str, input().split())) for _ in range(Q)]
load = Binary_Indexed_Tree(N+5)
B = [0]*N
for s,x,y in q[::-1]:
    x = int(x)
    y = int(y)
    if s=='A':
        num = load._sum(x)
        B[x-1] += y*num
    else:
        load.add(x-1,1)
        load.add(y,-1)
for i in range(N):
    num = load._sum(i+1)
    B[i] += A[i]*num
print(*B)
0