結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー | convexineq |
提出日時 | 2021-03-03 19:24:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 626 ms / 2,000 ms |
コード長 | 3,918 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 82,692 KB |
実行使用メモリ | 97,152 KB |
最終ジャッジ日時 | 2024-10-02 09:50:39 |
合計ジャッジ時間 | 10,659 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 544 ms
78,184 KB |
testcase_01 | AC | 615 ms
97,152 KB |
testcase_02 | AC | 626 ms
96,768 KB |
testcase_03 | AC | 624 ms
96,896 KB |
testcase_04 | AC | 622 ms
96,768 KB |
testcase_05 | AC | 619 ms
97,024 KB |
testcase_06 | AC | 354 ms
83,764 KB |
testcase_07 | AC | 268 ms
86,656 KB |
testcase_08 | AC | 520 ms
92,332 KB |
testcase_09 | AC | 580 ms
84,960 KB |
testcase_10 | AC | 452 ms
92,372 KB |
testcase_11 | AC | 426 ms
87,572 KB |
testcase_12 | AC | 483 ms
93,824 KB |
testcase_13 | AC | 493 ms
79,616 KB |
testcase_14 | AC | 327 ms
78,688 KB |
testcase_15 | AC | 446 ms
81,512 KB |
testcase_16 | AC | 45 ms
54,784 KB |
testcase_17 | AC | 45 ms
55,552 KB |
testcase_18 | AC | 45 ms
55,040 KB |
testcase_19 | AC | 44 ms
55,168 KB |
testcase_20 | AC | 45 ms
55,040 KB |
ソースコード
class LazySegmentTree: def __init__(self, op_X, e_X, mapping, compose, id_M, N, array=None): __slots__ = ["op_X","e_X","mapping","compose","id_M","N","log","N0","data","lazy"] # それぞれ Xの演算、単位元、f(x), f\circ g, Xの恒等変換 self.e_X = e_X; self.op_X = op_X; self.mapping = mapping; self.compose = compose; self.id_M = id_M self.N = N self.log = (N-1).bit_length() self.N0 = 1<<self.log self.data = [e_X]*(2*self.N0) self.lazy = [id_M]*self.N0 if array is not None: assert N == len(array) self.data[self.N0:self.N0+self.N] = array for i in range(self.N0-1,0,-1): self.update(i) # 1点更新 def point_set(self, p, x): p += self.N0 for i in range(self.log, 0,-1): self.push(p>>i) self.data[p] = x for i in range(1, self.log + 1): self.update(p>>i) # 1点取得 def point_get(self, p): p += self.N0 for i in range(self.log, 0, -1): self.push(p>>i) return self.data[p] # 半開区間[L,R)をopでまとめる def prod(self, l, r): if l == r: return self.e_X l += self.N0 r += self.N0 for i in range(self.log, 0, -1): if (l>>i)<<i != l: self.push(l>>i) if (r>>i)<<i != r: self.push(r>>i) sml = smr = self.e_X while l < r: if l & 1: sml = self.op_X(sml, self.data[l]) l += 1 if r & 1: r -= 1 smr = self.op_X(self.data[r], smr) l >>= 1 r >>= 1 return self.op_X(sml, smr) # 全体をopでまとめる def all_prod(self): return self.data[1] # 1点作用 def apply_point(self, p, f): p += self.N0 for i in range(self.log, 0, -1): self.push(p>>i) self.data[p] = self.mapping(f, self.data[p]) for i in range(1, self.log + 1): self.update(p>>i) # 区間作用 def apply(self, l, r, f): if l == r: return l += self.N0 r += self.N0 for i in range(self.log, 0, -1): if (l>>i)<<i != l: self.push(l>>i) if (r>>i)<<i != r: self.push((r-1)>>i) l2, r2 = l, r while l < r: if l & 1: self.all_apply(l, f) l += 1 if r & 1: r -= 1 self.all_apply(r, f) l >>= 1 r >>= 1 l, r = l2, r2 for i in range(1, self.log + 1): if (l>>i)<<i != l: self.update(l>>i) if (r>>i)<<i != r: self.update((r-1)>>i) # 以下内部関数 def update(self, k): self.data[k] = self.op_X(self.data[2*k], self.data[2*k+1]) def all_apply(self, k, f): self.data[k] = self.mapping(f, self.data[k]) if k < self.N0: self.lazy[k] = self.compose(f, self.lazy[k]) def push(self, k): #propagate と同じ if self.lazy[k] is self.id_M: return self.data[2*k ] = self.mapping(self.lazy[k], self.data[2*k]) self.data[2*k+1] = self.mapping(self.lazy[k], self.data[2*k+1]) if 2*k < self.N0: self.lazy[2*k] = self.compose(self.lazy[k], self.lazy[2*k]) self.lazy[2*k+1] = self.compose(self.lazy[k], self.lazy[2*k+1]) self.lazy[k] = self.id_M n = int(input()) *t, = map(int,input().split()) a = [0]*n a[0] = 3*(n-1) for i in range(1,n): a[i] = t[i-1] + 3*(n-i) from operator import add seg = LazySegmentTree(op_X=max, e_X=0, mapping=add, compose=add, id_M=0, N=n, array=a) m = int(input()) for _ in range(m): L,R,D = map(int,input().split()) seg.apply(L,R+1,D) print(seg.all_prod())