結果
問題 | No.875 Range Mindex Query |
ユーザー | shimonohnishi |
提出日時 | 2024-06-09 13:52:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 518 ms / 2,000 ms |
コード長 | 3,182 bytes |
コンパイル時間 | 225 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 107,764 KB |
最終ジャッジ日時 | 2024-06-09 13:53:02 |
合計ジャッジ時間 | 5,633 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
53,668 KB |
testcase_01 | AC | 62 ms
69,512 KB |
testcase_02 | AC | 78 ms
73,876 KB |
testcase_03 | AC | 40 ms
61,160 KB |
testcase_04 | AC | 49 ms
64,560 KB |
testcase_05 | AC | 46 ms
60,740 KB |
testcase_06 | AC | 59 ms
67,960 KB |
testcase_07 | AC | 68 ms
72,244 KB |
testcase_08 | AC | 54 ms
65,228 KB |
testcase_09 | AC | 57 ms
66,036 KB |
testcase_10 | AC | 73 ms
74,104 KB |
testcase_11 | AC | 465 ms
100,588 KB |
testcase_12 | AC | 448 ms
92,096 KB |
testcase_13 | AC | 414 ms
107,248 KB |
testcase_14 | AC | 424 ms
103,956 KB |
testcase_15 | AC | 513 ms
107,632 KB |
testcase_16 | AC | 471 ms
107,648 KB |
testcase_17 | AC | 518 ms
107,764 KB |
testcase_18 | AC | 478 ms
107,488 KB |
ソースコード
class segtree(): n = 1 size = 1 log = 2 d = [0] op = None e = 10**15 def __init__(self, V, OP, E): self.n = len(V) self.op = OP self.e = E self.log = (self.n - 1).bit_length() self.size = 1 << self.log self.d = [E for i in range(2 * self.size)] for i in range(self.n): self.d[self.size + i] = V[i] for i in range(self.size - 1, 0, -1): self.update(i) def set(self, p, x): assert 0 <= p and p < self.n p += self.size self.d[p] = x for i in range(1, self.log + 1): self.update(p >> i) def get(self, p): assert 0 <= p and p < self.n return self.d[p + self.size] def prod(self, l, r): assert 0 <= l and l <= r and r <= self.n sml = self.e smr = self.e l += self.size r += self.size while (l < r): if (l & 1): sml = self.op(sml, self.d[l]) l += 1 if (r & 1): smr = self.op(self.d[r - 1], smr) r -= 1 l >>= 1 r >>= 1 return self.op(sml, smr) def all_prod(self): return self.d[1] def max_right(self, l, f): assert 0 <= l and l <= self.n assert f(self.e) if l == self.n: return self.n l += self.size sm = self.e while (1): while (l % 2 == 0): l >>= 1 if not (f(self.op(sm, self.d[l]))): while (l < self.size): l = 2 * l if f(self.op(sm, self.d[l])): sm = self.op(sm, self.d[l]) l += 1 return l - self.size sm = self.op(sm, self.d[l]) l += 1 if (l & -l) == l: break return self.n def min_left(self, r, f): assert 0 <= r and r <= self.n assert f(self.e) if r == 0: return 0 r += self.size sm = self.e while (1): r -= 1 while (r > 1 and (r % 2)): r >>= 1 if not (f(self.op(self.d[r], sm))): while (r < self.size): r = (2 * r + 1) if f(self.op(self.d[r], sm)): sm = self.op(self.d[r], sm) r -= 1 return r + 1 - self.size sm = self.op(self.d[r], sm) if (r & -r) == r: break return 0 def update(self, k): self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) N, Q = map(int, input().split()) A = list(map(int, input().split())) st = segtree(A, min, 10**15) d = {a: i for i, a in enumerate(A)} for _ in range(Q): t, l, r = map(int, input().split()) if t == 1: a, b = st.get(l - 1), st.get(r - 1) d[a], d[b] = d[b], d[a] st.set(l - 1, b) st.set(r - 1, a) else: m = st.prod(l - 1, r) print(d[m] + 1)