結果
問題 | No.1234 典型RMQ |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-04-09 16:35:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 352 ms / 2,000 ms |
コード長 | 5,117 bytes |
コンパイル時間 | 351 ms |
コンパイル使用メモリ | 82,600 KB |
実行使用メモリ | 92,968 KB |
最終ジャッジ日時 | 2024-10-04 19:16:05 |
合計ジャッジ時間 | 10,810 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
57,680 KB |
testcase_01 | AC | 39 ms
57,252 KB |
testcase_02 | AC | 41 ms
57,768 KB |
testcase_03 | AC | 40 ms
57,508 KB |
testcase_04 | AC | 40 ms
56,644 KB |
testcase_05 | AC | 40 ms
57,676 KB |
testcase_06 | AC | 350 ms
88,232 KB |
testcase_07 | AC | 312 ms
79,812 KB |
testcase_08 | AC | 347 ms
92,592 KB |
testcase_09 | AC | 322 ms
84,100 KB |
testcase_10 | AC | 341 ms
91,496 KB |
testcase_11 | AC | 334 ms
88,140 KB |
testcase_12 | AC | 329 ms
83,556 KB |
testcase_13 | AC | 324 ms
79,988 KB |
testcase_14 | AC | 343 ms
83,568 KB |
testcase_15 | AC | 320 ms
82,816 KB |
testcase_16 | AC | 331 ms
91,136 KB |
testcase_17 | AC | 319 ms
83,472 KB |
testcase_18 | AC | 296 ms
79,568 KB |
testcase_19 | AC | 344 ms
92,928 KB |
testcase_20 | AC | 259 ms
92,196 KB |
testcase_21 | AC | 334 ms
88,440 KB |
testcase_22 | AC | 334 ms
92,724 KB |
testcase_23 | AC | 336 ms
92,968 KB |
testcase_24 | AC | 330 ms
92,696 KB |
testcase_25 | AC | 347 ms
92,812 KB |
testcase_26 | AC | 352 ms
92,904 KB |
testcase_27 | AC | 42 ms
56,792 KB |
testcase_28 | AC | 41 ms
57,180 KB |
testcase_29 | AC | 39 ms
57,468 KB |
ソースコード
# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.buffer.readline class lazy_segtree(): def __init__(self, lst, ope, e, mapping, composition, id_): self.n = len(lst) self.log = (self.n - 1).bit_length() self.size = 1 << self.log self.data = [e for _ in range(2 * self.size)] self.lz = [id_ for _ in range(self.size)] self.e = e self.op = ope self.mapping = mapping self.composition = composition self.identity = id_ for i in range(self.n): self.data[self.size + i] = lst[i] for i in range(self.size - 1, 0, -1): self.update(i) def update(self, k): self.data[k] = self.op(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.size: self.lz[k] = self.composition(f, self.lz[k]) def push(self, k): self.all_apply(2 * k, self.lz[k]) self.all_apply(2 * k + 1, self.lz[k]) self.lz[k] = self.identity 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(self.log, 0, -1): self.push(p >> i) return self.data[p] def prod(self, 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, 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) def all_prod(self): return self.data[1] def apply_point(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 apply(self, l, r, f): 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, 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 max_right(self, l, g): if l == self.n: return self.n l += self.size for i in range(self.log, 0, -1): self.push(l >> i) sm = self.e while 1: while i % 2 == 0: l >>= 1 if not g(self.op(sm, self.data[l])): while l < self.size: self.push(l) l *= 2 if g(self.op(sm, self.data[l])): sm = self.op(sm, self.data[l]) l += 1 return l - self.size sm = self.op(sm, self.data[l]) l += 1 if l & -l == l: break return self.n def min_left(self, r, g): if r == 0: return 0 r += self.size for i in range(self.log, 0, -1): self.push((r - 1) >> i) sm = self.e while 1: r -= 1 while r > 1 and r % 2 == 1: r >>= 1 if not g(self.op(self.data[r], sm)): while r < self.size: self.push(r) r = 2 * r + 1 if g(self.op(self.data[r], sm)): sm = self.op(self.data[r], sm) r -= 1 return r + 1 - self.size sm = self.op(self.data[r], sm) if r & -r == r: break return 0 ope = lambda x,y : min(x,y) ide_ele = (1<<60) mapping = lambda f,x : x+f composition = lambda f,g : f+g id_ = 0 N = int(input()) A = list(map(int,input().split())) Q = int(input()) T = lazy_segtree(A, ope, ide_ele, mapping, composition, id_) for _ in range(Q): k,l,r,c = map(int,input().split()) if k==1: l -= 1 T.apply(l,r,c) else: l -= 1 print(T.prod(l,r))