結果

問題 No.875 Range Mindex Query
ユーザー rkato5680
提出日時 2020-08-24 08:55:16
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,462 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 25,940 KB
最終ジャッジ日時 2024-11-06 05:48:50
合計ジャッジ時間 5,789 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 10 TLE * 1 -- * 7
権限があれば一括ダウンロードができます

ソースコード

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 binary_search2(func, n_min, n_max):
    left,right=n_min,n_max
    y_left, y_right = func(left), func(right)
    while right-left>1:
        middle = (left+right)//2
        y_middle = func(middle)
        if y_left==y_middle: left=middle
        else: right=middle

    return left
        
def index_search(idx):
    return rmq.query(idx,idx+1)==MIN

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_search2(index_search,l,r+1)+1
        print(idx)
0