結果

問題 No.1000 Point Add and Array Add
ユーザー qqqqqqqq
提出日時 2020-03-26 19:02:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 86,168 KB
実行使用メモリ 142,384 KB
最終ジャッジ日時 2023-08-30 13:13:41
合計ジャッジ時間 9,021 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,108 KB
testcase_01 AC 73 ms
71,188 KB
testcase_02 AC 71 ms
71,172 KB
testcase_03 AC 71 ms
71,292 KB
testcase_04 AC 73 ms
71,052 KB
testcase_05 AC 71 ms
71,052 KB
testcase_06 AC 69 ms
71,252 KB
testcase_07 AC 72 ms
70,968 KB
testcase_08 AC 70 ms
71,244 KB
testcase_09 AC 72 ms
71,260 KB
testcase_10 AC 68 ms
70,908 KB
testcase_11 AC 71 ms
71,236 KB
testcase_12 AC 103 ms
76,708 KB
testcase_13 AC 94 ms
77,116 KB
testcase_14 AC 105 ms
78,308 KB
testcase_15 AC 105 ms
77,852 KB
testcase_16 AC 336 ms
114,680 KB
testcase_17 AC 304 ms
113,200 KB
testcase_18 AC 425 ms
142,384 KB
testcase_19 AC 426 ms
142,100 KB
testcase_20 AC 383 ms
139,060 KB
testcase_21 AC 394 ms
142,032 KB
testcase_22 AC 398 ms
141,900 KB
testcase_23 AC 414 ms
142,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class Binary_Indexed_Tree_RAQ():
    def __init__(self, n):
        self.data = [0]*(n+1)
        self.n = n+1

    def __add(self, ind, num):
        while(ind <= self.n):
            self.data[ind - 1] += num
            ind += ind & -ind

    # [s, t]
    def range_add(self, s, t, x):
        s += 1
        t += 1
        self.__add(s,x)
        self.__add(t+1,-x)

    # [0, i]
    def query(self, i):
        i += 1
        ret = 0
        while(i > 0):
            ret += self.data[i-1]
            i -= i & -i
        return ret

n,q = map(int, input().split())
a = list(map(int, input().split()))
cxy = [input().split() for i in range(q)]
b = [0]*n
BIT = Binary_Indexed_Tree_RAQ(n)
for c,x,y in reversed(cxy):
    x,y = int(x)-1, int(y)
    if c == "A":
        b[x] += BIT.query(x)*y
    else:
        BIT.range_add(x, y-1, 1)
for i in range(n):
    b[i] += BIT.query(i)*a[i]

print(*b)
0