結果
問題 | No.1000 Point Add and Array Add |
ユーザー | yuly3 |
提出日時 | 2020-04-28 11:05:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 968 ms / 2,000 ms |
コード長 | 3,925 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 183,624 KB |
最終ジャッジ日時 | 2024-11-24 06:26:24 |
合計ジャッジ時間 | 10,414 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,864 KB |
testcase_01 | AC | 36 ms
52,992 KB |
testcase_02 | AC | 36 ms
52,608 KB |
testcase_03 | AC | 35 ms
52,608 KB |
testcase_04 | AC | 35 ms
52,480 KB |
testcase_05 | AC | 36 ms
52,224 KB |
testcase_06 | AC | 34 ms
52,992 KB |
testcase_07 | AC | 34 ms
52,224 KB |
testcase_08 | AC | 34 ms
52,480 KB |
testcase_09 | AC | 33 ms
52,864 KB |
testcase_10 | AC | 33 ms
52,864 KB |
testcase_11 | AC | 34 ms
52,352 KB |
testcase_12 | AC | 97 ms
77,304 KB |
testcase_13 | AC | 93 ms
77,424 KB |
testcase_14 | AC | 111 ms
79,004 KB |
testcase_15 | AC | 100 ms
78,280 KB |
testcase_16 | AC | 693 ms
150,732 KB |
testcase_17 | AC | 597 ms
132,812 KB |
testcase_18 | AC | 902 ms
183,624 KB |
testcase_19 | AC | 921 ms
183,112 KB |
testcase_20 | AC | 677 ms
181,304 KB |
testcase_21 | AC | 905 ms
183,104 KB |
testcase_22 | AC | 875 ms
183,116 KB |
testcase_23 | AC | 968 ms
183,224 KB |
ソースコード
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline class LazySegmentTree: def __init__(self, init_value: list, segfunc, ide_ele=0, lazy_ide_ele=0): self.ide_ele = ide_ele self.lazy_ide_ele = lazy_ide_ele self.segfunc = segfunc n = len(init_value) self.N0 = 1 << (n - 1).bit_length() self.data = [self.ide_ele] * (2 * self.N0) self.lazy = [self.lazy_ide_ele] * (2 * self.N0) for i, x in enumerate(init_value): self.data[i + self.N0 - 1] = x for i in range(self.N0 - 2, -1, -1): self.data[i] = segfunc(self.data[2 * i + 1], self.data[2 * i + 2]) 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.data[2 * idx + 1] += v self.data[2 * idx + 2] += v self.lazy[2 * idx + 1] += v self.lazy[2 * idx + 2] += v ################################################################ self.lazy[idx] = self.lazy_ide_ele def update(self, left, right, x): ids = tuple(self.gindex(left, right)) ################################################################ # self.propagates(*ids) ################################################################ L = self.N0 + left R = self.N0 + right while L < R: if R & 1: R -= 1 ################################################################ self.lazy[R - 1] += x self.data[R - 1] += x ################################################################ if L & 1: ################################################################ self.lazy[L - 1] += x self.data[L - 1] += x ################################################################ L += 1 L >>= 1 R >>= 1 for i in ids: idx = i - 1 self.data[idx] = self.segfunc(self.data[2 * idx + 1], self.data[2 * idx + 2]) + self.lazy[idx] def query(self, left, right): self.propagates(*self.gindex(left, right)) L = left + self.N0 R = right + self.N0 res = self.ide_ele ################################################################ while L < R: if L & 1: res = self.segfunc(res, self.data[L - 1]) L += 1 if R & 1: R -= 1 res = self.segfunc(res, self.data[R - 1]) L >>= 1 R >>= 1 ################################################################ return res 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)]) segfunc = lambda _, b: b lazy_seg_tree = LazySegmentTree([0] * N, segfunc) ans = [0] * N for c, x, y in reversed(query): x -= 1 if c == 'B': lazy_seg_tree.update(x, y, 1) else: ans[x] += y * lazy_seg_tree.query(x, x + 1) print(*ans) if __name__ == '__main__': solve()