結果
問題 | No.1000 Point Add and Array Add |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:18:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 353 ms / 2,000 ms |
コード長 | 1,528 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,908 KB |
実行使用メモリ | 159,872 KB |
最終ジャッジ日時 | 2025-03-20 20:19:51 |
合計ジャッジ時間 | 6,155 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
class BIT: def __init__(self, size): self.n = size self.tree = [0] * (self.n + 2) # 1-based indexing def add(self, idx, delta): while idx <= self.n: self.tree[idx] += delta idx += idx & -idx def query(self, idx): res = 0 while idx > 0: res += self.tree[idx] idx -= idx & -idx return res def main(): import sys input = sys.stdin.read().split() ptr = 0 n = int(input[ptr]) ptr += 1 q = int(input[ptr]) ptr += 1 A = list(map(int, input[ptr:ptr+n])) ptr += n current_A = A.copy() sum_y_cb = [0] * n sum_y = [0] * n bit = BIT(n) for _ in range(q): c = input[ptr] ptr += 1 x = int(input[ptr]) ptr += 1 y = int(input[ptr]) ptr += 1 if c == 'A': x_idx = x - 1 # Convert to 0-based index cnt_b = bit.query(x) # x is 1-based for BIT sum_y_cb[x_idx] += y * cnt_b current_A[x_idx] += y sum_y[x_idx] += y else: # B-type query: apply range [x, y] x_start = x y_end = y bit.add(x_start, 1) if y_end + 1 <= n: bit.add(y_end + 1, -1) B = [] for i in range(n): cnt_b = bit.query(i + 1) # i+1 is 1-based for BIT b_i = current_A[i] * cnt_b - sum_y_cb[i] B.append(str(b_i)) print(' '.join(B)) if __name__ == "__main__": main()