結果

問題 No.875 Range Mindex Query
ユーザー pynomipynomi
提出日時 2019-09-07 18:44:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,319 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 149,836 KB
最終ジャッジ日時 2023-09-09 07:43:17
合計ジャッジ時間 13,095 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

inf = float('inf')

class SegmentTree:
    def __init__(self, N):
        self.N = 2**(N-1).bit_length()
        self.data = [[inf, -1]] * (2*self.N)

    def update(self, k, x):
        k += self.N-1
        self.data[k] = [x, k-(self.N-1)]
        while k >= 0:
            k = (k - 1) // 2
            if self.data[2*k+1] < self.data[2*k+2]:
                self.data[k] = self.data[2*k+1][:]
            else:
                self.data[k] = self.data[2*k+2][:]
    
    def query(self, l, r):
        L = l + self.N
        R = r + self.N
        s = [inf, -1]
        while L < R:
            if R & 1:
                R -= 1
                if s > self.data[R-1]:
                    s = self.data[R-1][:]
            if L & 1:
                if s > self.data[L-1]:
                    s = self.data[L-1][:]
                L += 1
            L >>= 1; R >>= 1
        return s

N, Q = map(int,input().split())
A = list(map(int,input().split()))
query = [list(map(int,input().split())) for _ in range(Q)]

st = SegmentTree(N)

for i, a in enumerate(A):
    st.update(i, a)

for q, l, r in query:
    l -= 1
    r -= 1
    if q == 1:
        al, li = st.query(l,l+1)
        ar, ri = st.query(r,r+1)
        st.update(l, ar)
        st.update(r, al)
    elif q == 2:
        m, i = st.query(l,r+1)
        print(i)
0