結果

問題 No.875 Range Mindex Query
ユーザー nephrologistnephrologist
提出日時 2020-05-06 21:12:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,274 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 24,664 KB
最終ジャッジ日時 2023-09-16 07:29:26
合計ジャッジ時間 12,567 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,024 KB
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 #

n, q = map(int, input().split())
A = list(map(int, input().split()))

infi = 10 ** 20


def func(pair1, pair2):
    idx1, val1 = pair1
    idx2, val2 = pair2
    if val1 < val2:
        res = pair1
    else:
        res = pair2
    return res


class SegmentTree:
    # 1-index
    def __init__(self, A: list, ele, func):  # Aは0-idx
        self.A = A
        self.ele = ele
        self.func = func
        self.n = len(self.A)
        self.num = 2 ** ((n - 1).bit_length())
        self.SEG = [self.ele] * (2 * self.num)

    #     self.LAZY=[ele]*(2*num)
    def search(self, idx):
        return self.SEG[idx + self.num - 1]

    def initialize(self):
        for i in range(self.n):
            self.SEG[i + self.num] = (i + 1, self.A[i])
        for i in range(self.num - 1, 0, -1):
            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1])

    def update(self, idx, val):  # 1-idx
        idx += self.num - 1
        self.SEG[idx] = val
        idx //= 2
        while idx:
            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1])
            idx //= 2

    # def delay(self,):

    def query(self, left, right):
        # maspy式。開区間のママ処理する
        # left, rightで値を分けているのは交換法則不成立のときのため
        # 開区間→Rが奇数→右端が偶数→1ずらしてから計算
        #  下から上への遷移は2で割る
        # juppy氏は閉区間に直していた
        resleft = self.ele
        resright = self.ele
        left += self.num
        right += self.num
        while right - left > 0:
            if left % 2 == 1:
                resleft = self.func(resleft, self.SEG[left])
                left += 1
            if right % 2 == 1:
                right -= 1
                resright = self.func(resright, self.SEG[right])
            left //= 2
            right //= 2
        return self.func(resleft, resright)[0]


ST = SegmentTree(A, (-1, infi), func)
ST.initialize()

for _ in range(q):
    a, l, r = map(int, input().split())
    if a == 1:
        lidx, lval = ST.search(l)
        ridx, rval = ST.search(r)
        ST.update(ridx, (ridx, lval))
        ST.update(lidx, (lidx, rval))
    else:
        print(ST.query(l, r + 1))
0