結果
問題 |
No.3122 Median of Medians of Division
|
ユーザー |
|
提出日時 | 2025-04-17 08:57:05 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 4,024 ms / 2,000 ms |
コード長 | 1,754 bytes |
コンパイル時間 | 907 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 45,752 KB |
最終ジャッジ日時 | 2025-04-17 09:14:37 |
合計ジャッジ時間 | 120,388 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 40 |
ソースコード
def op(a, b): if a[0] < b[0]: a, b = b, a if a[1] < b[0]: return (a[0], b[0]) else: return a class SegmentTree: def __init__(self, n): self.n = 1 while self.n < n: self.n <<= 1 self.data = [(0, 0) for _ in range(2 * self.n)] self.has_built = False def set(self, i, x): if self.has_built: raise Exception("Cannot set after build") self.data[i + self.n] = x def build(self): for i in range(self.n - 1, 0, -1): self.data[i] = op(self.data[2 * i], self.data[2 * i + 1]) self.has_built = True def update(self, i, x): i += self.n self.data[i] = x while i > 1: i >>= 1 self.data[i] = op(self.data[2 * i], self.data[2 * i + 1]) def query(self, l, r): l += self.n r += self.n res = (0, 0) while l < r: if l & 1: res = op(res, self.data[l]) l += 1 if r & 1: r -= 1 res = op(res, self.data[r]) l >>= 1 r >>= 1 return res n, q = map(int, input().split()) a = list(map(int, input().split())) seg = SegmentTree(n-1) for i in range(n-1): seg.set(i, (min(a[i], a[i+1]), 0)) seg.build() for _ in range(q): query = list(map(int, input().split())) if query[0] == 1: i, x = query[1]-1, query[2] a[i] = x if i > 0: seg.update(i-1, (min(a[i], a[i-1]), 0)) if i < n-1: seg.update(i, (min(a[i], a[i+1]), 0)) else: l, r = query[1]-1, query[2]-1 res = op(op((a[l], 0), seg.query(l, r)), (a[r], 0)) print(res[1])