結果
問題 | No.875 Range Mindex Query |
ユーザー | dango |
提出日時 | 2023-07-08 09:17:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,479 ms / 2,000 ms |
コード長 | 1,358 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 87,108 KB |
実行使用メモリ | 93,956 KB |
最終ジャッジ日時 | 2023-09-29 10:33:57 |
合計ジャッジ時間 | 11,355 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
71,860 KB |
testcase_01 | AC | 119 ms
77,876 KB |
testcase_02 | AC | 125 ms
78,016 KB |
testcase_03 | AC | 82 ms
76,284 KB |
testcase_04 | AC | 109 ms
77,508 KB |
testcase_05 | AC | 82 ms
76,504 KB |
testcase_06 | AC | 112 ms
77,980 KB |
testcase_07 | AC | 128 ms
77,668 KB |
testcase_08 | AC | 107 ms
77,368 KB |
testcase_09 | AC | 104 ms
78,384 KB |
testcase_10 | AC | 156 ms
77,976 KB |
testcase_11 | AC | 1,022 ms
90,512 KB |
testcase_12 | AC | 859 ms
86,064 KB |
testcase_13 | AC | 755 ms
93,956 KB |
testcase_14 | AC | 750 ms
92,068 KB |
testcase_15 | AC | 902 ms
93,876 KB |
testcase_16 | AC | 1,398 ms
93,632 KB |
testcase_17 | AC | 1,479 ms
93,928 KB |
testcase_18 | AC | 1,248 ms
93,860 KB |
ソースコード
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)