結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー | brthyyjp |
提出日時 | 2021-03-03 11:22:11 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,925 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 109,824 KB |
最終ジャッジ日時 | 2024-10-03 03:10:19 |
合計ジャッジ時間 | 11,328 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
ソースコード
class LazySegTree: # RMQ and RAQ def __init__(self, init_val, seg_ide, lazy_ide, segfunc): self.n = len(init_val) self.num = 2**(self.n-1).bit_length() self.seg_ide = seg_ide self.lazy_ide = lazy_ide self.segfunc = segfunc # seg, lazy: 1-indexed self.seg = [seg_ide]*2*self.num for i in range(self.n): self.seg[i+self.num] = init_val[i] for i in range(self.num-1, 0, -1): self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1]) self.lazy = [lazy_ide]*2*self.num def gindex(self, l, r): # l, r: 1-indexed L = l + self.num R = r + self.num lm = (L // (L & -L)) >> 1 rm = (R // (R & -R)) >> 1 while L < R: if R <= rm: yield R if L <= lm: yield L L = L >> 1 R = R >> 1 while L: yield L L = L >> 1 def propagate(self, *ids): # ids: 1-indexed for i in reversed(ids): v = self.lazy[i] if v == self.lazy_ide: continue self.lazy[2*i] += v self.lazy[2*i+1] += v self.seg[2*i] += v self.seg[2*i+1] += v self.lazy[i] = self.lazy_ide def update(self, l, r, x): # l, r: 0-indexed # add x to [l, r) L = l + self.num R = r + self.num while L < R: if R & 1: R -= 1 self.lazy[R] += x self.seg[R] += x if L & 1: self.lazy[L] += x self.seg[L] += x L += 1 L = L >> 1 R = R >> 1 for i in self.gindex(l, r): # i: 1-indexed self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1]) + self.lazy[i] def query(self, l, r): # l, r: 0-indexed # query for [l, r) if r <= l: return self.seg_ide self.propagate(*self.gindex(l, r)) L = l + self.num R = r + self.num res = self.seg_ide while L < R: if R & 1: R -= 1 res = self.segfunc(res, self.seg[R]) if L & 1: res = self.segfunc(self.seg[L], res) L += 1 L = L >> 1 R = R >> 1 return res def __str__(self): # for debug arr = [self.query(i,i+1) for i in range(self.n)] return str(arr) import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) T = list(map(int, input().split())) T = [t+3*(n-1-i) for i, t in enumerate(T)] print(T) seg = LazySegTree(T, 0, 0, max) m = int(input()) for i in range(m): l, r, d = map(int, input().split()) l, r = l-1, r-1 seg.update(l, r+1, d) print(seg.query(0, n))