結果
問題 |
No.3198 Monotonic Query
|
ユーザー |
|
提出日時 | 2025-07-01 11:26:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,074 ms / 3,000 ms |
コード長 | 1,468 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 82,652 KB |
実行使用メモリ | 97,912 KB |
最終ジャッジ日時 | 2025-07-12 10:49:46 |
合計ジャッジ時間 | 21,036 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
import sys # Pythonの再帰上限を増やす sys.setrecursionlimit(10**6) class SegTree: def __init__(self, n, identity_element): self.n = 1 while self.n < n: self.n *= 2 self.identity = identity_element self.dat = [self.identity] * (2 * self.n - 1) def update(self, k, a): k += self.n - 1 self.dat[k] = a while k > 0: k = (k - 1) // 2 self.dat[k] = max(self.dat[k * 2 + 1], self.dat[k * 2 + 2]) def _query(self, a, b, k, l, r): if r <= a or b <= l: return self.identity if a <= l and r <= b: return self.dat[k] vl = self._query(a, b, k * 2 + 1, l, (l + r) // 2) vr = self._query(a, b, k * 2 + 2, (l + r) / 2, r) return max(vl, vr) def query(self, a, b): # [a, b) の区間でクエリ return self._query(a, b, 0, 0, self.n) def main(): input = sys.stdin.readline Q = int(input()) seg = SegTree(Q, 0) # 最小値は0と仮定 count = 0 output = [] for _ in range(Q): query = list(map(int, input().split())) if query[0] == 1: x = query[1] seg.update(count, x) count += 1 else: k = query[1] result = seg.query(count - k, count) output.append(str(result)) print("\n".join(output)) if __name__ == "__main__": main()