結果

問題 No.1000 Point Add and Array Add
ユーザー mkawa2mkawa2
提出日時 2020-02-28 22:06:04
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 142,036 KB
最終ジャッジ日時 2023-08-03 20:32:18
合計ジャッジ時間 7,649 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,212 KB
testcase_01 AC 74 ms
71,268 KB
testcase_02 AC 74 ms
71,212 KB
testcase_03 AC 74 ms
71,368 KB
testcase_04 AC 75 ms
71,160 KB
testcase_05 AC 75 ms
71,168 KB
testcase_06 AC 74 ms
71,436 KB
testcase_07 AC 75 ms
71,348 KB
testcase_08 AC 73 ms
71,048 KB
testcase_09 AC 72 ms
71,220 KB
testcase_10 AC 73 ms
71,332 KB
testcase_11 AC 71 ms
71,088 KB
testcase_12 AC 116 ms
78,004 KB
testcase_13 AC 112 ms
78,144 KB
testcase_14 AC 116 ms
78,424 KB
testcase_15 AC 116 ms
77,904 KB
testcase_16 AC 358 ms
124,008 KB
testcase_17 AC 344 ms
114,620 KB
testcase_18 AC 464 ms
142,016 KB
testcase_19 AC 467 ms
142,036 KB
testcase_20 AC 421 ms
138,900 KB
testcase_21 AC 438 ms
141,728 KB
testcase_22 AC 451 ms
141,748 KB
testcase_23 AC 452 ms
141,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

class BitSum:
    def __init__(self, n):
        self.n = n + 3
        self.table = [0] * (self.n + 1)

    def add(self, i, x):
        i += 1
        while i <= self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    n,q=MI()
    aa=LI()
    cxy=[input().split() for _ in range(q)]
    bit=BitSum(n+1)
    bb=[0]*n
    for c,x,y in cxy[::-1]:
        x,y=int(x),int(y)
        if c=="A":
            x-=1
            k=bit.sum(x)
            bb[x]+=k*y
        else:
            x,y=x-1,y-1
            bit.add(x,1)
            bit.add(y+1,-1)
    for i in range(n):
        k=bit.sum(i)
        bb[i]+=k*aa[i]
    print(*bb)

main()
0