結果

問題 No.1000 Point Add and Array Add
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-02-28 23:32:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,233 ms / 2,000 ms
コード長 1,302 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 164,408 KB
最終ジャッジ日時 2024-04-21 20:55:04
合計ジャッジ時間 10,147 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,632 KB
testcase_01 AC 39 ms
54,016 KB
testcase_02 AC 38 ms
54,272 KB
testcase_03 AC 39 ms
54,272 KB
testcase_04 AC 38 ms
54,016 KB
testcase_05 AC 38 ms
53,888 KB
testcase_06 AC 40 ms
54,144 KB
testcase_07 AC 39 ms
54,144 KB
testcase_08 AC 38 ms
54,016 KB
testcase_09 AC 38 ms
53,632 KB
testcase_10 AC 39 ms
54,144 KB
testcase_11 AC 39 ms
54,016 KB
testcase_12 AC 73 ms
75,264 KB
testcase_13 AC 71 ms
75,008 KB
testcase_14 AC 91 ms
78,776 KB
testcase_15 AC 73 ms
75,520 KB
testcase_16 AC 613 ms
114,648 KB
testcase_17 AC 665 ms
112,004 KB
testcase_18 AC 980 ms
142,028 KB
testcase_19 AC 972 ms
142,360 KB
testcase_20 AC 681 ms
132,652 KB
testcase_21 AC 1,213 ms
164,408 KB
testcase_22 AC 729 ms
132,644 KB
testcase_23 AC 1,233 ms
155,688 KB
権限があれば一括ダウンロードができます

ソースコード

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