結果

問題 No.875 Range Mindex Query
ユーザー maspymaspy
提出日時 2019-09-06 23:17:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,090 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 50,092 KB
最終ジャッジ日時 2023-09-07 02:31:32
合計ジャッジ時間 12,428 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
29,648 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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+1].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,data[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