結果

問題 No.875 Range Mindex Query
ユーザー rkato5680rkato5680
提出日時 2020-08-24 09:07:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,413 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 24,596 KB
最終ジャッジ日時 2024-04-23 23:44:29
合計ジャッジ時間 4,365 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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
    
def search(left,right):
    return rmq.query(left,right+1)==MIN
    
def binary_search(func,left,right):
    while right-left>1:
        middle = (left+right)//2
        if func(left,middle):
            right = middle
        else:
            left = middle
    if func(left,left+1):return left
    else:return right

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

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