結果

問題 No.1000 Point Add and Array Add
ユーザー H3PO4H3PO4
提出日時 2021-08-21 19:08:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 894 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 39,924 KB
最終ジャッジ日時 2024-04-23 09:49:34
合計ジャッジ時間 17,360 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,624 KB
testcase_01 AC 26 ms
10,624 KB
testcase_02 AC 27 ms
10,624 KB
testcase_03 AC 26 ms
10,624 KB
testcase_04 AC 27 ms
10,624 KB
testcase_05 AC 27 ms
10,624 KB
testcase_06 AC 36 ms
10,624 KB
testcase_07 AC 28 ms
10,624 KB
testcase_08 AC 27 ms
10,624 KB
testcase_09 AC 26 ms
10,624 KB
testcase_10 AC 26 ms
10,624 KB
testcase_11 AC 26 ms
10,496 KB
testcase_12 AC 35 ms
10,752 KB
testcase_13 AC 32 ms
10,624 KB
testcase_14 AC 41 ms
10,880 KB
testcase_15 AC 36 ms
11,136 KB
testcase_16 AC 1,410 ms
33,788 KB
testcase_17 AC 1,245 ms
25,180 KB
testcase_18 TLE -
testcase_19 AC 1,994 ms
38,772 KB
testcase_20 AC 1,779 ms
32,960 KB
testcase_21 AC 1,466 ms
35,284 KB
testcase_22 TLE -
testcase_23 AC 1,619 ms
36,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline

N, Q = map(int, input().split())
A = list(map(int, input().split()))


class Bit:
    """1-indexed"""

    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


bit = Bit(N + 1)
ans = [0] * N
for _ in range(Q):
    c, x, y = input().split()
    x, y = int(x), int(y)
    if c == 'A':
        n = bit.sum(x)
        ans[x - 1] += n * A[x - 1]
        bit.add(x, -n)
        bit.add(x + 1, n)
        A[x - 1] += y

    else:
        # assert c == 'B'
        bit.add(x, 1)
        bit.add(y + 1, -1)

for x in range(1, N + 1):
    n = bit.sum(x)
    ans[x - 1] += n * A[x - 1]
print(*ans)
0