結果

問題 No.875 Range Mindex Query
ユーザー pynomipynomi
提出日時 2019-09-06 22:38:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,195 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 58,876 KB
最終ジャッジ日時 2023-09-07 01:32:44
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,464 KB
testcase_01 AC 26 ms
8,612 KB
testcase_02 AC 29 ms
8,596 KB
testcase_03 AC 18 ms
8,452 KB
testcase_04 AC 22 ms
8,068 KB
testcase_05 AC 28 ms
8,644 KB
testcase_06 AC 26 ms
8,504 KB
testcase_07 AC 23 ms
8,076 KB
testcase_08 AC 23 ms
8,564 KB
testcase_09 AC 21 ms
8,044 KB
testcase_10 AC 30 ms
8,504 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, Q = map(int,input().split())
A = list(map(int,input().split()))
queries = [[int(e)-1 for e in input().split()] for _ in range(Q)]

# N: 処理する区間の長さ
N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [[INF,-1] for _ in range(2*N0)]

# a_k の値を x に更新
def update(k, x):
    data[k+N0-1] = [x, k]
    k += N0-1
    while k >= 0:
        k = (k - 1) // 2
        if data[2*k+1][0] < data[2*k+2][0]:
            data[k] = data[2*k+1][:]
        else:
            data[k] = data[2*k+2][:]

# 区間[l, r)の(最小値, インデックス)
def query(l, r):
    L = l + N0; R = r + N0
    s = [INF,-1]
    while L < R:
        if R & 1:
            R -= 1
            if s[0] > data[R-1][0]:
                s = data[R-1]
        if L & 1:
            if s[0] > data[L-1][0]:
                s = data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s

# 配列の初期化
for i, a in enumerate(A):
    update(i, a)

def solve(q, l, r):
    if q == 0:
        al, li = query(l, l+1)
        ar, ri = query(r, r+1)
        update(l, ar)
        update(r, al)
    elif q == 1:
        m, i = query(l,r+1)
        print(i+1)

for q, l, r in queries:
    solve(q, l, r)
0