結果

問題 No.875 Range Mindex Query
ユーザー wattaiheiwattaihei
提出日時 2019-10-11 14:01:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,373 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 61,620 KB
最終ジャッジ日時 2024-05-03 13:54:14
合計ジャッジ時間 18,311 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 36 ms
11,264 KB
testcase_02 AC 36 ms
11,008 KB
testcase_03 AC 26 ms
10,880 KB
testcase_04 AC 29 ms
11,008 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 34 ms
11,136 KB
testcase_07 AC 32 ms
10,880 KB
testcase_08 AC 35 ms
11,008 KB
testcase_09 AC 29 ms
11,136 KB
testcase_10 AC 39 ms
11,136 KB
testcase_11 TLE -
testcase_12 AC 1,823 ms
41,520 KB
testcase_13 AC 1,826 ms
50,232 KB
testcase_14 AC 1,775 ms
50,220 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
権限があれば一括ダウンロードができます

ソースコード

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

# 要素数を2の累乗にしておく
N = 1
while N < N_:
    N *= 2

# 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