結果

問題 No.1000 Point Add and Array Add
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-02-28 23:24:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,249 ms / 2,000 ms
コード長 1,344 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 164,876 KB
最終ジャッジ日時 2024-04-21 20:50:12
合計ジャッジ時間 11,316 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,760 KB
testcase_01 AC 45 ms
53,760 KB
testcase_02 AC 44 ms
53,760 KB
testcase_03 AC 43 ms
54,016 KB
testcase_04 AC 43 ms
53,888 KB
testcase_05 AC 46 ms
53,760 KB
testcase_06 AC 44 ms
54,272 KB
testcase_07 AC 44 ms
53,376 KB
testcase_08 AC 45 ms
54,144 KB
testcase_09 AC 44 ms
53,888 KB
testcase_10 AC 44 ms
53,504 KB
testcase_11 AC 44 ms
54,272 KB
testcase_12 AC 92 ms
76,032 KB
testcase_13 AC 90 ms
76,160 KB
testcase_14 AC 110 ms
78,400 KB
testcase_15 AC 92 ms
75,904 KB
testcase_16 AC 663 ms
114,708 KB
testcase_17 AC 694 ms
111,872 KB
testcase_18 AC 1,006 ms
141,892 KB
testcase_19 AC 1,011 ms
142,224 KB
testcase_20 AC 697 ms
133,132 KB
testcase_21 AC 1,249 ms
164,876 KB
testcase_22 AC 748 ms
132,308 KB
testcase_23 AC 1,248 ms
155,552 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+1)

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])
cc = 0
YY = [0]*N
ss = set()
j = 0
B = [0]*N
for i in range(N):
    while j < len(R):
        if R[j][1] == 1:
            B[R[j][0]//3] += (cc - bit.sum(R[j][3]+1)) * R[j][2]
            j += 1
            continue
        if R[j][0]//3 > i:
            break
        if R[j][0]//3 == i and R[j][1] == 2:
            break
        if R[j][1] == 0:
            cc += 1
            bit.add(R[j][2]+1, 1)
        elif R[j][1] == 2:
            cc -= 1
            bit.add(R[j][2]+1, -1)
        j += 1
    YY[i] = cc
#print(YY)
for i in range(N):
    B[i] += YY[i]*X[i]
print(*B)
0