結果
問題 | No.1234 典型RMQ |
ユーザー | tpyneriver |
提出日時 | 2020-09-19 04:25:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 437 ms / 2,000 ms |
コード長 | 3,437 bytes |
コンパイル時間 | 323 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 100,152 KB |
最終ジャッジ日時 | 2024-11-09 02:10:21 |
合計ジャッジ時間 | 11,203 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,480 KB |
testcase_01 | AC | 45 ms
52,992 KB |
testcase_02 | AC | 45 ms
53,632 KB |
testcase_03 | AC | 46 ms
53,376 KB |
testcase_04 | AC | 46 ms
53,276 KB |
testcase_05 | AC | 46 ms
53,376 KB |
testcase_06 | AC | 410 ms
94,464 KB |
testcase_07 | AC | 363 ms
83,700 KB |
testcase_08 | AC | 417 ms
99,584 KB |
testcase_09 | AC | 392 ms
86,804 KB |
testcase_10 | AC | 405 ms
97,616 KB |
testcase_11 | AC | 411 ms
94,336 KB |
testcase_12 | AC | 392 ms
86,476 KB |
testcase_13 | AC | 371 ms
84,468 KB |
testcase_14 | AC | 383 ms
86,460 KB |
testcase_15 | AC | 380 ms
86,256 KB |
testcase_16 | AC | 416 ms
97,492 KB |
testcase_17 | AC | 400 ms
85,908 KB |
testcase_18 | AC | 335 ms
84,540 KB |
testcase_19 | AC | 413 ms
99,840 KB |
testcase_20 | AC | 274 ms
99,072 KB |
testcase_21 | AC | 437 ms
94,720 KB |
testcase_22 | AC | 374 ms
99,720 KB |
testcase_23 | AC | 384 ms
99,652 KB |
testcase_24 | AC | 408 ms
100,096 KB |
testcase_25 | AC | 370 ms
100,096 KB |
testcase_26 | AC | 371 ms
100,152 KB |
testcase_27 | AC | 42 ms
52,992 KB |
testcase_28 | AC | 41 ms
53,248 KB |
testcase_29 | AC | 43 ms
53,340 KB |
ソースコード
import sys readline = sys.stdin.readline from operator import add class Lazysegtree: def __init__(self, A, fx, ex, fm, em, fa, initialize = True): #fa(operator, idx)の形にしている、data[idx]の長さに依存する場合などのため self.N = len(A) self.N0 = 2**(self.N-1).bit_length() self.fx = fx self.fm = fm self.ex = ex self.em = em self.lazy = [em]*(2*self.N0) if initialize: self.data = [self.ex]*self.N0 + A + [self.ex]*(self.N0 - self.N) for i in range(self.N0-1, -1, -1): self.data[i] = self.fx(self.data[2*i], self.data[2*i+1]) else: self.data = [self.ex]*(2*self.N0) def fa(self, ope, idx): return ope + self.data[idx] def __repr__(self): s = 'data' l = 'lazy' cnt = 1 for i in range(self.N0.bit_length()): s = '\n'.join((s, ' '.join(map(str, self.data[cnt:cnt+(1<<i)])))) l = '\n'.join((l, ' '.join(map(str, self.lazy[cnt:cnt+(1<<i)])))) cnt += 1<<i return '\n'.join((s, l)) def _ascend(self, k): k = k >> 1 c = k.bit_length() for j in range(c): idx = k >> j self.data[idx] = self.fx(self.data[2*idx], self.data[2*idx+1]) def _descend(self, k): k = k >> 1 idx = 1 c = k.bit_length() for j in range(1, c+1): idx = k >> (c - j) if self.lazy[idx] == self.em: continue self.data[2*idx] = self.fa(self.lazy[idx], 2*idx) self.data[2*idx+1] = self.fa(self.lazy[idx], 2*idx+1) self.lazy[2*idx] = self.fm(self.lazy[idx], self.lazy[2*idx]) self.lazy[2*idx+1] = self.fm(self.lazy[idx], self.lazy[2*idx+1]) self.lazy[idx] = self.em def query(self, l, r): L = l+self.N0 R = r+self.N0 self._descend(L//(L & -L)) self._descend(R//(R & -R)-1) sl = self.ex sr = self.ex while L < R: if R & 1: R -= 1 sr = self.fx(self.data[R], sr) if L & 1: sl = self.fx(sl, self.data[L]) L += 1 L >>= 1 R >>= 1 return self.fx(sl, sr) def operate(self, l, r, x): L = l+self.N0 R = r+self.N0 Li = L//(L & -L) Ri = R//(R & -R) self._descend(Li) self._descend(Ri-1) while L < R : if R & 1: R -= 1 self.data[R] = self.fa(x, R) self.lazy[R] = self.fm(x, self.lazy[R]) if L & 1: self.data[L] = self.fa(x, L) self.lazy[L] = self.fm(x, self.lazy[L]) L += 1 L >>= 1 R >>= 1 self._ascend(Li) self._ascend(Ri-1) N = int(readline()) A = list(map(int, readline().split())) INF = 10**18+3 T = Lazysegtree(A, min, INF, add, 0, None, initialize = True) Ans = [] Q = int(readline()) for _ in range(Q): k, l, r, c = map(int, readline().split()) if k == 1: T.operate(l-1, r, c) else: Ans.append(T.query(l-1, r)) print('\n'.join(map(str, Ans)))