結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
29,768 KB
testcase_01 AC 142 ms
29,864 KB
testcase_02 AC 144 ms
29,928 KB
testcase_03 AC 136 ms
29,776 KB
testcase_04 AC 138 ms
29,900 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 137 ms
29,904 KB
testcase_08 AC 137 ms
29,788 KB
testcase_09 AC 135 ms
29,696 KB
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].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