結果

問題 No.875 Range Mindex Query
ユーザー rkato5680rkato5680
提出日時 2020-08-24 09:37:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,157 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 28,328 KB
最終ジャッジ日時 2024-04-24 00:28:49
合計ジャッジ時間 19,895 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 38 ms
10,752 KB
testcase_02 AC 41 ms
10,752 KB
testcase_03 AC 34 ms
10,880 KB
testcase_04 AC 35 ms
10,880 KB
testcase_05 AC 38 ms
11,008 KB
testcase_06 AC 37 ms
11,008 KB
testcase_07 AC 36 ms
10,752 KB
testcase_08 AC 33 ms
10,880 KB
testcase_09 AC 32 ms
10,752 KB
testcase_10 AC 45 ms
11,008 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 1,968 ms
24,036 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

class RMQ:
    def __init__(self, N,INF=2**31-1):
        self.N0 = 2**(N-1).bit_length()
        self.INF=INF
        self.data = [INF]*(2*self.N0)

    def update(self, k, x):
        k += self.N0-1
        self.data[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.data[k] = min(self.data[2*k+1], self.data[2*k+2])

    def query(self, l, r):
        L = l + self.N0; R = r + self.N0
        s = self.INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])

            if L & 1:
                s = min(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

N,Q=map(int,input().split())
*A,=map(int,input().split())

rmq = RMQ(N+1)
indices = dict()
for i in range(N):
    a = A[i]
    rmq.update(i+1,a)
    indices[a] = i+1
    
for i in range(Q):
    n,l,r=map(int,input().split())
    if n == 1:
        A[l-1],A[r-1] = A[r-1],A[l-1]
        rmq.update(l,A[l-1])
        rmq.update(r,A[r-1])
        indices[A[l-1]] = l
        indices[A[r-1]] = r
    else:
        MIN = rmq.query(l,r+1)
        idx = indices[MIN]
        print(idx)
0