結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
nehan_der_thal
|
| 提出日時 | 2020-03-01 02:51:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 391 ms / 2,000 ms |
| コード長 | 833 bytes |
| コンパイル時間 | 262 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 154,188 KB |
| 最終ジャッジ日時 | 2024-10-13 20:25:42 |
| 合計ジャッジ時間 | 5,912 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
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)
nehan_der_thal