結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-04-01 18:03:56 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,503 ms / 2,000 ms |
| コード長 | 1,677 bytes |
| 記録 | |
| コンパイル時間 | 109 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 32,460 KB |
| 最終ジャッジ日時 | 2024-06-27 01:56:48 |
| 合計ジャッジ時間 | 11,496 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, Q = map(int, readline().split())
A = [0] + list(map(int, readline().split()))
m = map(int, read().split())
query = zip(m, m, m)
class SegTree:
""" segment tree with point modification and range product. """
unit = 1 << 30
f = min
def __init__(self, N):
self.N = N
self.data = [self.unit] * (N + N)
def build(self, raw_data):
data = self.data
f = self.f
N = self.N
data[N:] = raw_data[:]
for i in range(N - 1, 0, -1):
data[i] = f(data[i << 1], data[i << 1 | 1])
def set_val(self, i, x):
data = self.data
f = self.f
i += self.N
data[i] = x
while i > 1:
data[i >> 1] = f(data[i], data[i ^ 1])
i >>= 1
def fold(self, L, R):
""" compute for [L, R) """
vL = vR = self.unit
data = self.data
f = self.f
L += self.N
R += self.N
while L < R:
if L & 1:
vL = f(vL, data[L])
L += 1
if R & 1:
R -= 1
vR = f(data[R], vR)
L >>= 1
R >>= 1
return f(vL, vR)
seg = SegTree(N + 1)
seg.build(A)
num_ind = [0] * (N + 1)
for i, x in enumerate(A):
num_ind[x] = i
for t, L, R in query:
if t == 1:
A[L], A[R] = A[R], A[L]
seg.set_val(L, A[L])
seg.set_val(R, A[R])
num_ind[A[L]], num_ind[A[R]] = L, R
else:
value = seg.fold(L, R + 1)
print(num_ind[value])
maspy