結果
問題 |
No.1705 Mode of long array
|
ユーザー |
![]() |
提出日時 | 2023-02-21 00:16:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 205 ms / 3,000 ms |
コード長 | 1,277 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 82,300 KB |
実行使用メモリ | 94,332 KB |
最終ジャッジ日時 | 2024-07-21 13:54:09 |
合計ジャッジ時間 | 12,097 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
import sys readline = sys.stdin.readline class SegmentTree: def __init__(self, size, f=max, default=0): self.size = 2**(size-1).bit_length() self.default = default self.dat = [default]*(self.size*2) self.f = f def update(self, i, x): i += self.size self.dat[i] = x while i > 0: i >>= 1 self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1]) def query(self, l, r): l += self.size r += self.size lres, rres = self.default, self.default while l < r: if l & 1: lres = self.f(lres, self.dat[l]) l += 1 if r & 1: r -= 1 rres = self.f(self.dat[r], rres) l >>= 1 r >>= 1 res = self.f(lres, rres) return res N, M = map(int, readline().split()) A = list(map(int, input().split())) T = SegmentTree(M) for i in range(M): T.update(i, A[i] * M + i) Q = int(readline()) for _ in range(Q): t, X, Y = map(int, readline().split()) X -= 1 if t == 1: A[X] += Y T.update(X, A[X] * M + X) elif t == 2: A[X] -= Y T.update(X, A[X] * M + X) else: print(T.query(0, M) % M + 1)