結果

問題 No.1000 Point Add and Array Add
ユーザー roarisroaris
提出日時 2020-07-24 23:48:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 152,932 KB
最終ジャッジ日時 2023-09-08 05:50:03
合計ジャッジ時間 6,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,420 KB
testcase_01 AC 68 ms
71,268 KB
testcase_02 AC 68 ms
71,432 KB
testcase_03 AC 70 ms
71,252 KB
testcase_04 AC 74 ms
71,164 KB
testcase_05 AC 68 ms
71,276 KB
testcase_06 AC 68 ms
71,332 KB
testcase_07 AC 69 ms
71,120 KB
testcase_08 AC 68 ms
71,400 KB
testcase_09 AC 68 ms
71,320 KB
testcase_10 AC 68 ms
71,384 KB
testcase_11 AC 65 ms
71,304 KB
testcase_12 AC 96 ms
76,852 KB
testcase_13 AC 88 ms
76,728 KB
testcase_14 AC 97 ms
78,064 KB
testcase_15 AC 93 ms
77,524 KB
testcase_16 AC 308 ms
130,984 KB
testcase_17 AC 305 ms
122,096 KB
testcase_18 AC 408 ms
152,304 KB
testcase_19 AC 419 ms
152,804 KB
testcase_20 AC 372 ms
149,688 KB
testcase_21 AC 405 ms
152,900 KB
testcase_22 AC 404 ms
152,932 KB
testcase_23 AC 411 ms
152,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

N, Q = map(int, input().split())
A = list(map(int, input().split()))
cxy = [tuple(input().split()) for _ in range(Q)]
ans = [0]*N
bit = BIT(N)

for c, x, y in cxy[::-1]:
    x, y = int(x), int(y)
    
    if c=='A':
        ans[x-1] += y*bit.acc(x)
    else:
        bit.add(x-1, 1)
        bit.add(y, -1)

for i in range(N):
    ans[i] += A[i]*bit.acc(i+1)
    
print(*ans)
0