結果

問題 No.875 Range Mindex Query
ユーザー tcltktcltk
提出日時 2021-09-04 03:54:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 1,756 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 115,068 KB
最終ジャッジ日時 2023-08-22 08:27:38
合計ジャッジ時間 9,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
80,964 KB
testcase_01 AC 225 ms
83,596 KB
testcase_02 AC 229 ms
83,664 KB
testcase_03 AC 210 ms
83,792 KB
testcase_04 AC 223 ms
83,560 KB
testcase_05 AC 208 ms
82,912 KB
testcase_06 AC 223 ms
83,684 KB
testcase_07 AC 233 ms
83,832 KB
testcase_08 AC 215 ms
83,620 KB
testcase_09 AC 218 ms
83,696 KB
testcase_10 AC 235 ms
83,704 KB
testcase_11 AC 528 ms
109,320 KB
testcase_12 AC 488 ms
100,528 KB
testcase_13 AC 481 ms
114,764 KB
testcase_14 AC 463 ms
112,108 KB
testcase_15 AC 530 ms
114,716 KB
testcase_16 AC 487 ms
115,068 KB
testcase_17 AC 502 ms
114,852 KB
testcase_18 AC 486 ms
114,988 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 = ([(INF, 0)] * self.N0) + a + ([(INF, 0)] * (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 = (INF, 0)
        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, i) for i, a in enumerate(A)])

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[0], l))
        seg_tree.update(r, (v_l[0], r))

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