結果

問題 No.875 Range Mindex Query
ユーザー tcltktcltk
提出日時 2021-09-04 03:49:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 460 ms / 2,000 ms
コード長 1,794 bytes
コンパイル時間 1,058 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 107,004 KB
最終ジャッジ日時 2023-08-22 08:19:50
合計ジャッジ時間 9,097 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 192 ms
80,784 KB
testcase_01 AC 209 ms
83,796 KB
testcase_02 AC 223 ms
83,900 KB
testcase_03 AC 204 ms
83,596 KB
testcase_04 AC 205 ms
83,768 KB
testcase_05 AC 201 ms
82,812 KB
testcase_06 AC 214 ms
83,852 KB
testcase_07 AC 218 ms
83,632 KB
testcase_08 AC 208 ms
83,468 KB
testcase_09 AC 219 ms
84,016 KB
testcase_10 AC 222 ms
83,748 KB
testcase_11 AC 440 ms
103,412 KB
testcase_12 AC 410 ms
96,796 KB
testcase_13 AC 404 ms
106,812 KB
testcase_14 AC 429 ms
104,864 KB
testcase_15 AC 439 ms
106,540 KB
testcase_16 AC 417 ms
106,544 KB
testcase_17 AC 460 ms
106,892 KB
testcase_18 AC 417 ms
107,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """3 3
# 2 1 3
# 2 1 3
# 1 2 3
# 2 1 3
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10


class SegTree_Update_QRMin:
    def __init__(self, a) -> None:
        n = len(a)
        self.N0 = 1 << (n-1).bit_length()
        self.data = ([2**31-1] * self.N0) + a + ([2**31-1] * (self.N0-n))
        for i in reversed(range(1, self.N0)):
            self.data[i] = min(self.data[i*2], self.data[i*2+1])
    
    def update(self, i, x):
        i += self.N0
        self.data[i] = x
        while i > 0:
            i >>= 1
            self.data[i] = min(self.data[i*2], self.data[i*2+1])
    def query_rmin(self, l, r):
        l += self.N0
        r += self.N0
        s = 2**31-1
        while l < r:
            if l & 1:
                s = min(s, self.data[l])
                l += 1
            if r & 1:
                s = min(s, self.data[r-1])
                r -= 1
            l >>= 1
            r >>= 1
        return s

    def get_value(self, i):
        return self.data[i+self.N0]


N, Q = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

seg_tree = SegTree_Update_QRMin(A)
T = [0] * N
for i, a in enumerate(A):
    T[a] = i

for _ in range(Q):
    i, l, r = map(int, input().split())
    l -= 1
    r -= 1
    if i == 1:
        v_l = seg_tree.get_value(l)
        v_r = seg_tree.get_value(r)
        seg_tree.update(l, v_r)
        seg_tree.update(r, v_l)
        T[v_l] = r
        T[v_r] = l

    else:
        m = seg_tree.query_rmin(l, r+1)
        ans = T[m] + 1
        print(ans)
0