結果
問題 | No.1000 Point Add and Array Add |
ユーザー |
![]() |
提出日時 | 2024-12-21 15:52:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 507 ms / 2,000 ms |
コード長 | 1,240 bytes |
コンパイル時間 | 431 ms |
コンパイル使用メモリ | 82,452 KB |
実行使用メモリ | 150,460 KB |
最終ジャッジ日時 | 2024-12-21 15:53:02 |
合計ジャッジ時間 | 7,359 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
import typingclass FenwickTree:'''Reference: https://en.wikipedia.org/wiki/Fenwick_tree'''def __init__(self, n: int = 0) -> None:self._n = nself.data = [0] * ndef add(self, p: int, x: typing.Any) -> None:assert 0 <= p < self._np += 1while p <= self._n:self.data[p - 1] += xp += p & -pdef sum(self, left: int, right: int) -> typing.Any:assert 0 <= left <= right <= self._nreturn self._sum(right) - self._sum(left)def _sum(self, r: int) -> typing.Any:s = 0while r > 0:s += self.data[r - 1]r -= r & -rreturn sfrom itertools import accumulateN,Q = map(int,input().split())A = list(map(int,input().split()))CXY = [input().split() for _ in range(Q)]ft = FenwickTree(N+1)B = [0] * NC = [0] * (N + 1)for c,x,y in CXY:if c == "B":x, y = int(x), int(y)C[x - 1] += 1C[y] -= 1C = list(accumulate(C))for c,x,y in CXY:x, y = int(x), int(y)if c == "B":ft.add(x-1,1)ft.add(y,-1)else:B[x-1] += y * (C[x-1] - ft.sum(0,x))for i in range(N):B[i] += A[i] * ft.sum(0,i + 1)print(*B)