結果
問題 |
No.8121 [Deleted]
|
ユーザー |
|
提出日時 | 2025-03-24 22:45:07 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,576 bytes |
コンパイル時間 | 203 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 40,984 KB |
最終ジャッジ日時 | 2025-03-24 22:45:36 |
合計ジャッジ時間 | 27,472 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | TLE * 10 |
ソースコード
import sys input = sys.stdin.readline output = sys.stdout.write class SegmentTree: def __init__(self, n): self.n = n self.dat = [0] * (2 * n) def add(self, i, x): i += self.n self.dat[i] += x i //= 2 while i: self.dat[i] = max(self.dat[2 * i], self.dat[2 * i + 1]) i //= 2 def mx(self, l, r): l += self.n r += self.n ret = 0 while r > l: if l & 1: ret = max(ret, self.dat[l]) l += 1 if r & 1: r -= 1 ret = max(ret, self.dat[r]) l //= 2 r //= 2 return ret def main(): # 最初の行: 配列のサイズとクエリ数 n, q = map(int, input().split()) seg = SegmentTree(n) # 配列の初期化 initial_values = list(map(int, input().split())) for i in range(n): seg.add(i, initial_values[i]) # クエリの処理 result = [] for _ in range(q): query = list(map(int, input().split())) if query[0] == 1: # クエリタイプ1: 値を加算 i, x = query[1], query[2] i -= 1 # 0-indexedに変換 seg.add(i, x) elif query[0] == 2: # クエリタイプ2: 区間最大値を取得 l, r = query[1], query[2] l -= 1 # 0-indexedに変換 result.append(seg.mx(l, r)) # 結果を出力 (まとめて書き出す) output("\n".join(map(str, result)) + "\n") if __name__ == "__main__": main()