結果

問題 No.875 Range Mindex Query
ユーザー maspymaspy
提出日時 2019-09-06 22:59:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,141 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 32,300 KB
最終ジャッジ日時 2023-09-07 02:05:26
合計ジャッジ時間 3,421 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys

N,Q = map(int,sys.stdin.readline().split())
A = [int(x) for x in sys.stdin.readline().split()]
query = [tuple(int(x)-1 for x in row.split()) for row in sys.stdin.readlines()]

INF = 10**6
size = 1<<3
data = [INF] * (2*size)
x_to_i = [None] * (N+1)
for i,x in enumerate(A):
    data[i+size] = x
    x_to_i[x] = i
for i in range(size-1,0,-1):
    data[i] = min(data[2*i],data[2*i+1])

def update(i,x):
    data[i+size] = x
    n = i+size
    while n > 1:
        n //= 2
        data[n] = min(data[2*n],data[2*n+1])


def RMQ(L,R):
    ret = INF
    R += 1 # 半開区間
    i = 1; iL = 0; iR = size
    q = [(i,iL,iR)]
    while q:
        i,iL,iR = q.pop()
        if R <= iL or iR <= L:
            continue
        if L<=iL and iR<=R:
            if ret > data[i]:
                ret = data[i]
            continue
        M = (iL+iR)//2
        q.append((2*i,iL,M))
        q.append((2*i+1,M,iR))
    return ret

for q,L,R in query:
    if q == 0:
        x,y = data[L+size],data[R+size]
        update(L,y)
        update(R,x)
        x_to_i[y] = L
        x_to_i[x] = R
    elif q == 1:
        print(x_to_i[RMQ(L,R)]+1)

0