結果

問題 No.875 Range Mindex Query
ユーザー pynomipynomi
提出日時 2019-09-07 19:08:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,081 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 86,184 KB
実行使用メモリ 168,272 KB
最終ジャッジ日時 2023-09-09 08:22:36
合計ジャッジ時間 9,947 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,680 KB
testcase_01 AC 117 ms
77,152 KB
testcase_02 AC 121 ms
77,244 KB
testcase_03 AC 82 ms
75,432 KB
testcase_04 AC 97 ms
76,224 KB
testcase_05 AC 92 ms
76,352 KB
testcase_06 AC 103 ms
76,320 KB
testcase_07 AC 109 ms
76,980 KB
testcase_08 AC 97 ms
76,284 KB
testcase_09 AC 99 ms
76,440 KB
testcase_10 AC 119 ms
76,996 KB
testcase_11 AC 1,081 ms
165,068 KB
testcase_12 AC 879 ms
140,760 KB
testcase_13 AC 882 ms
151,644 KB
testcase_14 AC 877 ms
151,264 KB
testcase_15 AC 1,062 ms
168,272 KB
testcase_16 AC 662 ms
131,372 KB
testcase_17 AC 693 ms
131,772 KB
testcase_18 AC 675 ms
132,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

inf = float('inf')

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

    def update(self, k, x):
        self.data[k+self.N-1] = [x, k]
        k += self.N-1
        while k >= 0:
            k = (k - 1) // 2
            if self.data[2*k+1][0] < self.data[2*k+2][0]:
                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[0] > self.data[R-1][0]:
                    s = self.data[R-1]
            if L & 1:
                if s[0] > self.data[L-1][0]:
                    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+1)
0