結果

問題 No.1000 Point Add and Array Add
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-02-28 23:19:08
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,430 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 173,192 KB
最終ジャッジ日時 2024-04-21 20:46:48
合計ジャッジ時間 14,447 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,016 KB
testcase_01 AC 41 ms
53,744 KB
testcase_02 AC 42 ms
54,016 KB
testcase_03 AC 42 ms
54,272 KB
testcase_04 AC 42 ms
53,632 KB
testcase_05 AC 42 ms
53,760 KB
testcase_06 AC 41 ms
53,900 KB
testcase_07 AC 42 ms
53,888 KB
testcase_08 AC 41 ms
54,016 KB
testcase_09 AC 42 ms
54,144 KB
testcase_10 AC 43 ms
54,272 KB
testcase_11 AC 42 ms
53,888 KB
testcase_12 AC 92 ms
78,464 KB
testcase_13 AC 84 ms
78,208 KB
testcase_14 AC 103 ms
78,800 KB
testcase_15 AC 94 ms
78,512 KB
testcase_16 AC 983 ms
124,904 KB
testcase_17 AC 1,067 ms
124,908 KB
testcase_18 AC 1,542 ms
158,296 KB
testcase_19 AC 1,538 ms
157,636 KB
testcase_20 AC 1,017 ms
137,732 KB
testcase_21 TLE -
testcase_22 AC 1,150 ms
144,456 KB
testcase_23 AC 1,891 ms
169,968 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, 1, b, x))
    else:
        R.append((a-1, 0, x))
        R.append((b-1, 2, x))
R.sort(key=lambda x: (x[0], x[1]))
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:
#            print(R[j])
#            print(segtree.query(0, R[j][3]))
            B[R[j][0]] += (bit.sum(MM) - bit.sum(R[j][3]+1)) * R[j][2]
#            print(ss)
            j += 1
            continue
        if R[j][0] > i:
            break
        if R[j][0] == 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