結果

問題 No.1000 Point Add and Array Add
ユーザー 👑 rin204rin204
提出日時 2022-07-04 18:05:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 1,359 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 104,732 KB
最終ジャッジ日時 2023-08-21 01:52:31
合計ジャッジ時間 9,882 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,220 KB
testcase_01 AC 72 ms
71,156 KB
testcase_02 AC 72 ms
70,872 KB
testcase_03 AC 72 ms
71,128 KB
testcase_04 AC 72 ms
71,156 KB
testcase_05 AC 71 ms
71,016 KB
testcase_06 AC 72 ms
71,080 KB
testcase_07 AC 72 ms
71,092 KB
testcase_08 AC 70 ms
71,044 KB
testcase_09 AC 71 ms
71,016 KB
testcase_10 AC 71 ms
71,040 KB
testcase_11 AC 72 ms
71,220 KB
testcase_12 AC 150 ms
78,600 KB
testcase_13 AC 115 ms
78,524 KB
testcase_14 AC 128 ms
78,500 KB
testcase_15 AC 122 ms
78,604 KB
testcase_16 AC 330 ms
101,488 KB
testcase_17 AC 292 ms
93,000 KB
testcase_18 AC 421 ms
104,656 KB
testcase_19 AC 427 ms
104,700 KB
testcase_20 AC 443 ms
103,992 KB
testcase_21 AC 364 ms
104,220 KB
testcase_22 AC 450 ms
104,128 KB
testcase_23 AC 387 ms
104,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    def __init__(self, n):
        self.size = n
        self.n0 = 1 << (n.bit_length() - 1)
        self.tree = [0] * (n + 1)
    
    def range_sum(self, l, r):
        return self.sum(r - 1) - self.sum(l - 1)
        
    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
        
    def get(self, i):
        return self.sum(i) - self.sum(i - 1)
 
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
         
    def lower_bound(self, x):
        pos = 0
        plus = self.n0
        while plus > 0:
            if pos + plus <= self.size and self.tree[pos + plus] < x:
                x -= self.tree[pos + plus]
                pos += plus
            plus //= 2
        return pos

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

for i in range(n):
    ans[i] += bit.sum(i) * A[i]
print(*ans)
0