結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-09 13:52:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 635 ms / 2,000 ms |
| コード長 | 3,182 bytes |
| コンパイル時間 | 850 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 107,648 KB |
| 最終ジャッジ日時 | 2024-12-30 03:40:35 |
| 合計ジャッジ時間 | 7,624 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
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)