結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
wattaihei
|
| 提出日時 | 2020-02-28 21:49:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 401 ms / 2,000 ms |
| コード長 | 1,159 bytes |
| コンパイル時間 | 150 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 153,432 KB |
| 最終ジャッジ日時 | 2024-10-13 17:14:28 |
| 合計ジャッジ時間 | 5,419 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
# 足す時は0~iまで一律に足し、返すのはi番目の値
class imosBIT():
def __init__(self, N):
self.N = N
self.bit = [0 for _ in range(self.N+1)]
def __str__(self):
ret = []
for i in range(1, self.N+1):
ret.append(self.__getitem__(i))
return "[" + ", ".join([str(a) for a in ret]) + "]"
def __getitem__(self, i):
s = 0
while i <= self.N:
s += self.bit[i]
i += i & -i
return s
def add(self, i, x):
while i > 0:
self.bit[i] += x
i -= i & -i
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
A = list(map(int, input().split()))
Query = []
for _ in range(Q):
a, b, c = map(str, input().split())
Query.append((a=="A", int(b), int(c)))
bit = imosBIT(N)
P = []
for isA, x, y in Query:
if isA:
p = bit[x]
# x番目は今pで、yをたす
P.append((x, p, y))
else:
bit.add(y, 1)
bit.add(x-1, -1)
ans = []
for i, a in enumerate(A):
ans.append(bit[i+1]*a)
for x, p, y in P:
ans[x-1] += y*(bit[x]-p)
print(*ans)
wattaihei