結果

問題 No.1000 Point Add and Array Add
ユーザー hedwig100
提出日時 2020-04-15 14:55:52
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,432 ms / 2,000 ms
コード長 1,207 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 44,704 KB
最終ジャッジ日時 2024-10-01 18:45:33
合計ジャッジ時間 12,194 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from bisect import bisect_left

class BinaryIndexedTree():

    def __init__(self,init_val):
        self.bit = [0] + init_val
        self.n  = len(init_val)

    def sum(self,i):
        ret = 0
        while i > 0:
            ret += self.bit[i]
            i -= (i & -i)
        return ret
    
    def add(self,i,x):
        while i <= self.n:
            self.bit[i] += x
            i += (i & -i)


def main():
    n,q = map(int,input().split())
    a = list(map(int,input().split()))
    b = [0] * n
    cnt = [0] * n
    bit = BinaryIndexedTree([0] * n)

    for _ in range(q):
        t,x,y = map(str,input().split())
        x = int(x)
        y = int(y)
        if t == 'A':
            c = bit.sum(x)
            b[x - 1] -= c * y
            a[x - 1] += y
        else:
            cnt[x - 1] += 1
            bit.add(x,1)
            if y < n:
                cnt[y] -= 1
                bit.add(y + 1,-1)
    
    b[0] += cnt[0] * a[0]
    for i in range(1,n):
        cnt[i] += cnt[i - 1]
        b[i] += cnt[i] * a[i]

    print(*b)

if __name__ == '__main__':
    main()
0