結果
問題 | No.1234 典型RMQ |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2020-09-29 15:47:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 767 ms / 2,000 ms |
コード長 | 3,523 bytes |
コンパイル時間 | 282 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 97,404 KB |
最終ジャッジ日時 | 2024-11-09 02:29:24 |
合計ジャッジ時間 | 16,539 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
52,608 KB |
testcase_01 | AC | 43 ms
53,248 KB |
testcase_02 | AC | 44 ms
52,864 KB |
testcase_03 | AC | 43 ms
52,992 KB |
testcase_04 | AC | 44 ms
53,248 KB |
testcase_05 | AC | 44 ms
52,608 KB |
testcase_06 | AC | 752 ms
94,772 KB |
testcase_07 | AC | 583 ms
85,476 KB |
testcase_08 | AC | 755 ms
97,264 KB |
testcase_09 | AC | 691 ms
91,008 KB |
testcase_10 | AC | 748 ms
95,600 KB |
testcase_11 | AC | 735 ms
94,356 KB |
testcase_12 | AC | 661 ms
90,164 KB |
testcase_13 | AC | 599 ms
85,480 KB |
testcase_14 | AC | 672 ms
90,288 KB |
testcase_15 | AC | 653 ms
89,600 KB |
testcase_16 | AC | 747 ms
95,316 KB |
testcase_17 | AC | 681 ms
90,384 KB |
testcase_18 | AC | 554 ms
83,004 KB |
testcase_19 | AC | 767 ms
97,404 KB |
testcase_20 | AC | 469 ms
93,440 KB |
testcase_21 | AC | 700 ms
94,700 KB |
testcase_22 | AC | 585 ms
94,208 KB |
testcase_23 | AC | 604 ms
94,464 KB |
testcase_24 | AC | 590 ms
94,848 KB |
testcase_25 | AC | 596 ms
94,592 KB |
testcase_26 | AC | 592 ms
94,464 KB |
testcase_27 | AC | 43 ms
52,480 KB |
testcase_28 | AC | 44 ms
52,736 KB |
testcase_29 | AC | 44 ms
53,120 KB |
ソースコード
import sys input = sys.stdin.readline class LazySegTree: def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n-1).bit_length() self.size = 1 << self.log self.data = [e]*(2*self.size) self.lazy = [id]*(self.size) def update(self, k): self.data[k] = self.op(self.data[2*k],self.data[2*k+1]) def build(self, lis): for i, l in enumerate(lis,self.size): self.data[i] = l for i in range(self.size-1, 0, -1): self.update(i) def set(self, p, x): p += self.size 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) def get(self, p): p += self.size for i in range(1, self.log+1): self.push(p >> i) return self.data[p] def apply(self, p, f): p += self.size 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 range_apply(self, l, r, f): ''' change the value you define in "mapping" and "composition" of [l,r) ''' if l == r: return l += self.size r += self.size 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 = l r2 = r while l2 < r2: if l2 & 1: self.all_apply(l2, f) l2 += 1 if r2 & 1: r2 -= 1 self.all_apply(r2, f) l2 >>= 1 r2 >>= 1 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 all_apply(self, k, f): self.data[k] = self.mapping(f, self.data[k]) if k < self.size: self.lazy[k] = self.composition(f, self.lazy[k]) def push(self, k): self.all_apply(2*k, self.lazy[k]) self.all_apply(2*k+1, self.lazy[k]) self.lazy[k] = self.id def prod(self, l, r): ''' get the value you define in "op" of [l,r) ''' if l == r: return self.e l += self.size r += self.size 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 while l < r: if l & 1: sml = self.op(sml, self.data[l]) l += 1 if r & 1: r -= 1 smr = self.op(self.data[r], smr) l >>= 1 r >>= 1 return self.op(sml, smr) n = int(input()) l = list(map(int,input().split())) e = 10**40 def op(x, y): return min(x,y) def mapping(p, x): return x+p def composition(p, q): return p+q lazyseg = LazySegTree(n, op, e, mapping, composition, 0) lazyseg.build(l) q = int(input()) for i in range(q): k,l,r,c = map(int,input().split()) if k == 1: lazyseg.range_apply(l-1,r,c) else: print(lazyseg.prod(l-1,r))