結果

問題 No.875 Range Mindex Query
ユーザー maspymaspy
提出日時 2019-09-06 23:25:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,154 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 49,944 KB
最終ジャッジ日時 2023-09-07 02:40:33
合計ジャッジ時間 13,850 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
29,704 KB
testcase_01 AC 135 ms
29,680 KB
testcase_02 AC 135 ms
29,880 KB
testcase_03 AC 129 ms
29,660 KB
testcase_04 AC 135 ms
29,636 KB
testcase_05 AC 131 ms
29,648 KB
testcase_06 AC 134 ms
29,720 KB
testcase_07 AC 132 ms
29,848 KB
testcase_08 AC 130 ms
29,668 KB
testcase_09 AC 137 ms
29,792 KB
testcase_10 AC 136 ms
29,772 KB
testcase_11 AC 1,053 ms
49,836 KB
testcase_12 AC 906 ms
47,016 KB
testcase_13 AC 705 ms
42,528 KB
testcase_14 AC 733 ms
42,176 KB
testcase_15 AC 991 ms
47,940 KB
testcase_16 AC 1,055 ms
48,016 KB
testcase_17 AC 1,154 ms
49,944 KB
testcase_18 AC 1,073 ms
49,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np


N,Q = map(int,sys.stdin.readline().split())
INF = 10**6
size = 300
data = np.full(N+(-N)%size,INF,dtype=np.int32)
data[:N] = np.array(sys.stdin.readline().split(),dtype=np.int32)
query = [tuple(int(x)-1 for x in row.split()) for row in sys.stdin.readlines()]


x_to_i = [None] * (N+1)
for i,x in enumerate(data[:N]):
    x_to_i[x] = i

N += (-N)%size
Nbucket = N//size
bucket = np.array([data[i*size:(i+1)*size].min() for i in range(Nbucket)])


def RmQ(L,R):
    R += 1
    nL = L//size
    nR = R//size
    if nL == nR:
        return data[L:R].min()
    x = data[L:(nL+1)*size].min()
    if R%size != 0:
        x = min(x,data[nR*size:R].min())
    if nL+1 < nR:
        x = min(x,bucket[nL+1:nR].min())
    return x

for q,L,R in query:
    if q == 0:
        x,y = data[L],data[R]
        data[L] = y; data[R] = x
        iL = L//size; iR = R//size
        bucket[iL] = data[iL*size:iL*size+size].min()
        bucket[iR] = data[iR*size:iR*size+size].min()
        x_to_i[y] = L
        x_to_i[x] = R
    elif q == 1:
        print(x_to_i[RmQ(L,R)]+1)

0