結果

問題 No.1000 Point Add and Array Add
ユーザー stngstng
提出日時 2022-08-17 17:09:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 820 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,856 KB
実行使用メモリ 158,388 KB
最終ジャッジ日時 2024-04-15 06:21:16
合計ジャッジ時間 9,239 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,812 KB
testcase_01 AC 40 ms
53,568 KB
testcase_02 AC 38 ms
53,448 KB
testcase_03 AC 36 ms
53,628 KB
testcase_04 AC 37 ms
54,468 KB
testcase_05 AC 40 ms
53,696 KB
testcase_06 AC 37 ms
52,752 KB
testcase_07 AC 36 ms
53,012 KB
testcase_08 AC 36 ms
53,340 KB
testcase_09 AC 36 ms
53,092 KB
testcase_10 AC 37 ms
52,608 KB
testcase_11 AC 37 ms
53,420 KB
testcase_12 AC 97 ms
77,540 KB
testcase_13 AC 86 ms
77,544 KB
testcase_14 AC 114 ms
78,388 KB
testcase_15 AC 96 ms
77,520 KB
testcase_16 AC 523 ms
123,716 KB
testcase_17 AC 483 ms
123,960 KB
testcase_18 AC 730 ms
145,984 KB
testcase_19 AC 721 ms
146,368 KB
testcase_20 AC 813 ms
158,388 KB
testcase_21 AC 533 ms
130,748 KB
testcase_22 AC 820 ms
158,172 KB
testcase_23 AC 590 ms
133,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    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

class RangeUpdate:
    def __init__(self, n):
        self.p = Bit(n + 1)
        self.q = Bit(n + 1)
     
    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)
     
    def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - \
               self.p.sum(s) - self.q.sum(s) * s
    #yukicoder218B

n,q = map(int,input().split())
a = [int(i) for i in input().split()]
cxy = [input().split() for j in range(q)]

ru = RangeUpdate(n+1)

add = []

for i in range(q):
    c,x,y = cxy[i]
    x,y = int(x),int(y)
    if c == "A":
        tmp = ru.sum(x,x)
        add.append([x,y,tmp])
    else:
        ru.add(x,y,1)

b = [0]*n
for i in range(n):
    b[i] = ru.sum(i+1,i+1)*a[i]

for i in range(len(add)):
    x,y,tmp = add[i]
    b[x-1] += y*(ru.sum(x,x)-tmp)

print(*b)
0