結果
問題 | No.1000 Point Add and Array Add |
ユーザー | yuly3 |
提出日時 | 2020-07-15 22:59:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 761 ms / 2,000 ms |
コード長 | 2,192 bytes |
コンパイル時間 | 252 ms |
コンパイル使用メモリ | 81,848 KB |
実行使用メモリ | 179,068 KB |
最終ジャッジ日時 | 2024-11-22 15:36:19 |
合計ジャッジ時間 | 8,274 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
52,480 KB |
testcase_01 | AC | 42 ms
52,480 KB |
testcase_02 | AC | 40 ms
52,608 KB |
testcase_03 | AC | 39 ms
52,864 KB |
testcase_04 | AC | 39 ms
52,992 KB |
testcase_05 | AC | 41 ms
52,864 KB |
testcase_06 | AC | 40 ms
52,352 KB |
testcase_07 | AC | 40 ms
52,352 KB |
testcase_08 | AC | 40 ms
52,480 KB |
testcase_09 | AC | 40 ms
52,352 KB |
testcase_10 | AC | 41 ms
52,480 KB |
testcase_11 | AC | 40 ms
52,736 KB |
testcase_12 | AC | 94 ms
77,440 KB |
testcase_13 | AC | 88 ms
77,184 KB |
testcase_14 | AC | 108 ms
78,080 KB |
testcase_15 | AC | 98 ms
77,760 KB |
testcase_16 | AC | 556 ms
145,812 KB |
testcase_17 | AC | 467 ms
130,344 KB |
testcase_18 | AC | 731 ms
179,068 KB |
testcase_19 | AC | 697 ms
178,548 KB |
testcase_20 | AC | 691 ms
175,216 KB |
testcase_21 | AC | 614 ms
178,552 KB |
testcase_22 | AC | 761 ms
178,568 KB |
testcase_23 | AC | 658 ms
178,688 KB |
ソースコード
import sys from operator import add sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline class DualSegmentTree: def __init__(self, size: int, segfunc, lazy_ide_ele=0): self.lazy_ide_ele = lazy_ide_ele self.segfunc = segfunc self.N0 = 1 << (size - 1).bit_length() self.lazy = [self.lazy_ide_ele] * (2 * self.N0) def gindex(self, left, right): L = left + self.N0 R = right + self.N0 lm = (L // (L & -L)) >> 1 rm = (R // (R & -R)) >> 1 while L < R: if R <= rm: yield R if L <= lm: yield L L >>= 1 R >>= 1 while L: yield L L >>= 1 def propagates(self, *ids): for i in reversed(ids): idx = i - 1 v = self.lazy[idx] if v == self.lazy_ide_ele: continue self.lazy[2 * idx + 1] = self.segfunc(self.lazy[2 * idx + 1], v) self.lazy[2 * idx + 2] = self.segfunc(self.lazy[2 * idx + 2], v) self.lazy[idx] = self.lazy_ide_ele def update(self, left: int, right: int, x): L = self.N0 + left R = self.N0 + right while L < R: if R & 1: R -= 1 self.lazy[R - 1] = self.segfunc(self.lazy[R - 1], x) if L & 1: self.lazy[L - 1] = self.segfunc(self.lazy[L - 1], x) L += 1 L >>= 1 R >>= 1 def query(self, k: int): self.propagates(*self.gindex(k, k + 1)) return self.lazy[k + self.N0 - 1] def solve(): N, Q = map(int, rl().split()) A = list(map(int, rl().split())) query = [['A', idx + 1, ai] for idx, ai in enumerate(A)] for _ in range(Q): c, x, y = rl().split() query.append([c, int(x), int(y)]) dual_seg_tree = DualSegmentTree(N, add) ans = [0] * N for c, x, y in reversed(query): x -= 1 if c == 'B': dual_seg_tree.update(x, y, 1) else: ans[x] += y * dual_seg_tree.query(x) print(*ans) if __name__ == '__main__': solve()