結果

問題 No.875 Range Mindex Query
ユーザー wattaiheiwattaihei
提出日時 2019-10-11 14:04:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,301 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 51,916 KB
最終ジャッジ日時 2024-05-03 13:58:41
合計ジャッジ時間 9,010 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,880 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
input = sys.stdin.readline

N, Q = map(int, input().split())
A = list(map(int, input().split()))
Query = [list(map(lambda x: int(x)-1, input().split())) for _ in range(Q)]

# 初期化最大値
max_N = (1 << 31) - 1


# Segment Tree
seg = [[max_N, 0] for _ in range(2*N-1)]

# k番目の値(0-indexed)をaに変更
def update(k, a):
    k += N - 1
    seg[k][0] = a
    seg[k][1] = k-N+1
    while k > 0:
        k = (k-1)//2
        if seg[2*k+1][0] > seg[2*k+2][0]:
            seg[k] = seg[2*k+2]
        else:
            seg[k] = seg[2*k+1]

# [l, r)の最小値取得
# kがNodeの番号、対応する区間が[a, b)
def query_min(l, r, k=0, a=0, b=N):
    # 交差してなければmax_N
    if b <= l or r <= a:
        return [max_N, 0]
    # 含んでいたらNodeの値
    if l <= a and b <= r:
        return seg[k]
    # それ以外なら子を見る
    else:
        vl = query_min(l, r, k*2+1, a, (a+b)//2)
        vr = query_min(l, r, k*2+2, (a+b)//2, b)
        if vl[0] > vr[0]:
            return vr
        else:
            return vl

for i, a in enumerate(A):
    update(i, a)

for com, l, r in Query:
    if com == 0:
        al = seg[l+N-1][0]
        ar = seg[r+N-1][0]
        update(l, ar)
        update(r, al)
    else:
        print(query_min(l, r+1)[1]+1)
0