結果

問題 No.1000 Point Add and Array Add
ユーザー nehan_der_thal
提出日時 2020-02-28 23:32:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,028 ms / 2,000 ms
コード長 1,302 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 163,956 KB
最終ジャッジ日時 2024-10-13 19:17:40
合計ジャッジ時間 8,802 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
MM = 2*10**5
#segtree = SegTree([0]*MM,MM,0, lambda x,y:x+y)
bit = Bit(MM)

N, Q = map(int, input().split())
X = list(map(int, input().split()))

R = []
for x in range(Q):
    s, a, b = input().split()
    a, b = int(a), int(b)
    if s == "A":
        R.append(((a-1)*3+1, 1, b, x))
    else:
        R.append(((a-1)*3, 0, x))
        R.append(((b-1)*3+2, 2, x))
R.sort(key=lambda x: x[0])
YY = [0]*N
j = 0
B = [0]*N
cc = 0
for i in range(N):
    while j < len(R):
        tt = R[j]
        if tt[1] == 1:
            B[tt[0]//3] += (cc - bit.sum(tt[3]+1)) * tt[2]
            j += 1
            continue
        if tt[0]//3 > i or (tt[0]//3 == i and tt[1] == 2):
            break
        if tt[1] == 0:
            cc += 1
            bit.add(tt[2]+1, 1)
        elif tt[1] == 2:
            cc -= 1
            bit.add(tt[2]+1, -1)
        j += 1
    YY[i] = cc
#print(YY)
for i in range(N):
    B[i] += YY[i]*X[i]
print(*B)
0