結果

問題 No.875 Range Mindex Query
ユーザー maspymaspy
提出日時 2020-04-01 18:00:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 1,701 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 119,176 KB
最終ジャッジ日時 2023-09-09 08:43:43
合計ジャッジ時間 5,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,076 KB
testcase_01 AC 84 ms
75,432 KB
testcase_02 AC 91 ms
75,580 KB
testcase_03 AC 78 ms
75,180 KB
testcase_04 AC 82 ms
75,512 KB
testcase_05 AC 75 ms
71,124 KB
testcase_06 AC 86 ms
75,444 KB
testcase_07 AC 86 ms
75,436 KB
testcase_08 AC 80 ms
75,412 KB
testcase_09 AC 84 ms
75,080 KB
testcase_10 AC 90 ms
75,704 KB
testcase_11 AC 410 ms
115,768 KB
testcase_12 AC 352 ms
112,904 KB
testcase_13 AC 321 ms
114,676 KB
testcase_14 AC 316 ms
112,832 KB
testcase_15 AC 376 ms
119,176 KB
testcase_16 AC 354 ms
119,012 KB
testcase_17 AC 370 ms
115,932 KB
testcase_18 AC 366 ms
115,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Q = map(int, readline().split())
A = [0] + list(map(int, readline().split()))
m = map(int, read().split())
query = zip(m, m, m)


class SegTree:
    """ segment tree with point modification and range product. """
    unit = 1 << 30
    f = min

    def __init__(self, N):
        self.N = N
        self.data = [self.unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.unit
        data = self.data
        f = self.f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)


seg = SegTree(N + 1)
seg.build(A)

num_ind = [0] * (N + 1)
for i, x in enumerate(A):
    num_ind[x] = i


for t, L, R in query:
    if t == 1:
        x = A[L]
        y = A[R]
        A[L], A[R] = y, x
        seg.set_val(L, y)
        seg.set_val(R, x)
        num_ind[y] = L
        num_ind[x] = R
    else:
        value = seg.fold(L, R + 1)
        print(num_ind[value])
0