結果
問題 | No.1000 Point Add and Array Add |
ユーザー | yuly3 |
提出日時 | 2020-04-28 11:05:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,109 ms / 2,000 ms |
コード長 | 3,925 bytes |
コンパイル時間 | 432 ms |
コンパイル使用メモリ | 87,180 KB |
実行使用メモリ | 184,004 KB |
最終ジャッジ日時 | 2023-08-15 21:39:42 |
合計ジャッジ時間 | 13,827 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,308 KB |
testcase_01 | AC | 76 ms
71,284 KB |
testcase_02 | AC | 76 ms
71,264 KB |
testcase_03 | AC | 77 ms
71,096 KB |
testcase_04 | AC | 76 ms
71,344 KB |
testcase_05 | AC | 75 ms
71,312 KB |
testcase_06 | AC | 76 ms
71,528 KB |
testcase_07 | AC | 77 ms
71,292 KB |
testcase_08 | AC | 76 ms
71,396 KB |
testcase_09 | AC | 75 ms
71,432 KB |
testcase_10 | AC | 73 ms
71,592 KB |
testcase_11 | AC | 76 ms
71,496 KB |
testcase_12 | AC | 150 ms
79,100 KB |
testcase_13 | AC | 141 ms
78,344 KB |
testcase_14 | AC | 162 ms
80,136 KB |
testcase_15 | AC | 148 ms
79,688 KB |
testcase_16 | AC | 821 ms
159,996 KB |
testcase_17 | AC | 740 ms
136,556 KB |
testcase_18 | AC | 1,074 ms
183,780 KB |
testcase_19 | AC | 1,106 ms
183,972 KB |
testcase_20 | AC | 802 ms
181,688 KB |
testcase_21 | AC | 1,081 ms
183,904 KB |
testcase_22 | AC | 1,030 ms
184,004 KB |
testcase_23 | AC | 1,109 ms
183,820 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()