結果
問題 | No.875 Range Mindex Query |
ユーザー |
|
提出日時 | 2023-07-08 09:17:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,512 ms / 2,000 ms |
コード長 | 1,358 bytes |
コンパイル時間 | 377 ms |
コンパイル使用メモリ | 82,376 KB |
実行使用メモリ | 92,680 KB |
最終ジャッジ日時 | 2024-07-22 05:09:51 |
合計ジャッジ時間 | 10,940 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
import math def chmin(a, b): if a > b: a = b class SegmentTree: def __init__(self, sz): self.n = 2 ** math.ceil(math.log2(sz)) self.dat = [int(2 ** 31 - 1) // 3] * (self.n * 2 - 1) def update(self, i, x): k = i + self.n - 1 self.dat[k] = x while k > 0: k = (k - 1) // 2 self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2]) def rmin(self, ql, qr, i=0, il=0, ir=None): if ir is None: ir = self.n if qr <= il or ir <= ql: return int(2 ** 31 - 1) // 3 elif ql <= il and ir <= qr: return self.dat[i] else: m = (il + ir) // 2 return min( self.rmin(ql, qr, i * 2 + 1, il, m), self.rmin(ql, qr, i * 2 + 2, m, ir)) def get(self, i): return self.dat[i + self.n - 1] n, q = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) pos = [0] * n seg = SegmentTree(n) for i in range(n): pos[a[i]] = i seg.update(i, a[i]) for qq in range(q): t, i, j = map(int, input().split()) i -= 1 j -= 1 if t == 1: ei = seg.get(i) ej = seg.get(j) seg.update(i, ej) seg.update(j, ei) pos[ei] = j pos[ej] = i else: print(pos[seg.rmin(i, j + 1)] + 1)