結果

問題 No.1000 Point Add and Array Add
ユーザー titiatitia
提出日時 2020-02-28 21:49:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 688 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 179,980 KB
最終ジャッジ日時 2023-08-03 20:03:09
合計ジャッジ時間 8,982 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,732 KB
testcase_01 AC 96 ms
71,708 KB
testcase_02 AC 96 ms
71,448 KB
testcase_03 AC 97 ms
71,312 KB
testcase_04 AC 97 ms
71,704 KB
testcase_05 AC 96 ms
71,492 KB
testcase_06 AC 97 ms
71,600 KB
testcase_07 AC 97 ms
71,616 KB
testcase_08 AC 98 ms
71,656 KB
testcase_09 AC 97 ms
71,600 KB
testcase_10 AC 98 ms
71,344 KB
testcase_11 AC 98 ms
71,568 KB
testcase_12 AC 148 ms
81,416 KB
testcase_13 AC 137 ms
78,924 KB
testcase_14 AC 161 ms
82,152 KB
testcase_15 AC 146 ms
81,136 KB
testcase_16 AC 481 ms
141,920 KB
testcase_17 AC 460 ms
134,536 KB
testcase_18 AC 630 ms
172,196 KB
testcase_19 AC 638 ms
172,356 KB
testcase_20 AC 688 ms
177,304 KB
testcase_21 AC 498 ms
154,176 KB
testcase_22 AC 674 ms
179,980 KB
testcase_23 AC 543 ms
158,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Q=map(int,input().split())
A=list(map(int,input().split()))
Q=[tuple(input().split()) for i in range(Q)]


LEN=N+5

BIT=[0]*(LEN+1)# 1-indexedなtree

def update(v,w):# index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

from collections import defaultdict
check=defaultdict(list)

for c,x,y in Q:
    x=int(x)
    y=int(y)

    if c=="B":
        update(x,1)
        update(y+1,-1)

    else:
        check[x].append((getvalue(x),y))

ANS=[0]*N
for i in range(N):
    ANS[i]+=getvalue(i+1)*A[i]

#print(ANS)

for x in check:
    for c,y in check[x]:
        ANS[x-1]+=(getvalue(x)-c)*y

print(*ANS)
0