結果

問題 No.1000 Point Add and Array Add
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-03-01 02:51:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 413 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 1,069 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 154,616 KB
最終ジャッジ日時 2024-04-21 22:01:42
合計ジャッジ時間 5,944 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,608 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 AC 38 ms
51,968 KB
testcase_03 AC 37 ms
52,096 KB
testcase_04 AC 38 ms
52,096 KB
testcase_05 AC 37 ms
52,608 KB
testcase_06 AC 38 ms
52,224 KB
testcase_07 AC 38 ms
52,096 KB
testcase_08 AC 37 ms
52,096 KB
testcase_09 AC 37 ms
52,096 KB
testcase_10 AC 38 ms
52,224 KB
testcase_11 AC 38 ms
52,480 KB
testcase_12 AC 63 ms
70,272 KB
testcase_13 AC 62 ms
68,480 KB
testcase_14 AC 70 ms
75,008 KB
testcase_15 AC 70 ms
74,112 KB
testcase_16 AC 322 ms
127,360 KB
testcase_17 AC 281 ms
115,412 KB
testcase_18 AC 413 ms
154,376 KB
testcase_19 AC 413 ms
154,616 KB
testcase_20 AC 350 ms
151,052 KB
testcase_21 AC 382 ms
154,508 KB
testcase_22 AC 386 ms
154,272 KB
testcase_23 AC 393 ms
154,296 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
N, Q = map(int, input().split())
X = list(map(int, input().split()))
Qs = []
for i, x in enumerate(X):
    Qs.append((1, i, x))
for _ in range(Q):
    c, x, y = input().split()
    x, y = int(x), int(y)
    if c == "A":
        Qs.append((1, x-1, y))
    else:
        Qs.append((0, x-1, y-1))
Qs = Qs[::-1]
Y = [0]*N
bb = Bit(N+1)
for f, x, y in Qs:
    if f:
        Y[x] += y * bb.sum(x+1)
    else:
        bb.add(x+1, 1)
        bb.add(y+2, -1)
print(*Y)
0