結果

問題 No.1000 Point Add and Array Add
ユーザー maspymaspy
提出日時 2020-03-20 03:22:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,080 ms / 2,000 ms
コード長 1,822 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 11,044 KB
実行使用メモリ 48,056 KB
最終ジャッジ日時 2023-08-20 21:25:09
合計ジャッジ時間 11,066 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,092 KB
testcase_01 AC 18 ms
8,028 KB
testcase_02 AC 17 ms
8,052 KB
testcase_03 AC 17 ms
8,040 KB
testcase_04 AC 16 ms
8,200 KB
testcase_05 AC 16 ms
8,020 KB
testcase_06 AC 16 ms
8,072 KB
testcase_07 AC 17 ms
8,076 KB
testcase_08 AC 16 ms
8,032 KB
testcase_09 AC 16 ms
8,036 KB
testcase_10 AC 17 ms
8,100 KB
testcase_11 AC 16 ms
8,052 KB
testcase_12 AC 22 ms
8,052 KB
testcase_13 AC 21 ms
8,100 KB
testcase_14 AC 25 ms
8,724 KB
testcase_15 AC 22 ms
8,660 KB
testcase_16 AC 712 ms
40,664 KB
testcase_17 AC 654 ms
28,264 KB
testcase_18 AC 1,052 ms
46,676 KB
testcase_19 AC 1,061 ms
46,676 KB
testcase_20 AC 781 ms
37,984 KB
testcase_21 AC 1,040 ms
44,272 KB
testcase_22 AC 926 ms
48,056 KB
testcase_23 AC 1,080 ms
44,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


class BinaryIndexedTree():
    def __init__(self, seq):
        self.size = len(seq)
        self.depth = self.size.bit_length()
        self.build(seq)

    def build(self, seq):
        data = seq
        size = self.size
        for i, x in enumerate(data):
            j = i + (i & (-i))
            if j < size:
                data[j] += data[i]
        self.data = data

    def __repr__(self):
        return self.data.__repr__()

    def get_sum(self, i):
        data = self.data
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s

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

    def find_kth_element(self, k):
        data = self.data; size = self.size
        x, sx = 0, 0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + data[y]
            if sy < k:
                x, sx = y, sy
        return x + 1


N, Q = map(int, readline().split())
A = [0] + list(map(int, readline().split()))
B = [0] * (N + 1)
add_count = BinaryIndexedTree([0] * (N + 10))
for _ in range(Q):
    c, x, y = readline().split()
    x = int(x)
    y = int(y)
    if c == b'A':
        A[x] += y
        B[x] -= y * add_count.get_sum(x)
    else:
        add_count.add(x, 1)
        add_count.add(y + 1, -1)

C = add_count.data
for i in range(1, N + 10):
    j = i - (i & -i)
    C[i] += C[j]

answer = (c * a + b for a, b, c in zip(A[1:], B[1:], C[1:]))
print(' '.join(map(str, answer)))
0