結果

問題 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,226 ms / 2,000 ms
コード長 1,822 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 50,708 KB
最終ジャッジ日時 2024-05-08 03:44:18
合計ジャッジ時間 11,735 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
11,008 KB
testcase_01 AC 27 ms
11,008 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 34 ms
10,880 KB
testcase_04 AC 28 ms
11,008 KB
testcase_05 AC 26 ms
11,008 KB
testcase_06 AC 27 ms
11,008 KB
testcase_07 AC 27 ms
11,008 KB
testcase_08 AC 28 ms
11,008 KB
testcase_09 AC 29 ms
11,008 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 27 ms
11,008 KB
testcase_12 AC 34 ms
11,136 KB
testcase_13 AC 32 ms
11,008 KB
testcase_14 AC 37 ms
11,136 KB
testcase_15 AC 34 ms
11,264 KB
testcase_16 AC 802 ms
43,180 KB
testcase_17 AC 723 ms
30,844 KB
testcase_18 AC 1,152 ms
49,524 KB
testcase_19 AC 1,136 ms
49,584 KB
testcase_20 AC 832 ms
37,396 KB
testcase_21 AC 1,226 ms
46,940 KB
testcase_22 AC 969 ms
50,708 KB
testcase_23 AC 1,196 ms
47,604 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