結果

問題 No.875 Range Mindex Query
ユーザー terasaterasa
提出日時 2022-06-29 13:52:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 2,323 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 107,336 KB
最終ジャッジ日時 2024-05-02 04:59:14
合計ジャッジ時間 5,589 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
54,528 KB
testcase_01 AC 74 ms
65,536 KB
testcase_02 AC 91 ms
69,632 KB
testcase_03 AC 63 ms
61,184 KB
testcase_04 AC 70 ms
64,000 KB
testcase_05 AC 57 ms
56,192 KB
testcase_06 AC 73 ms
65,920 KB
testcase_07 AC 77 ms
66,688 KB
testcase_08 AC 66 ms
63,616 KB
testcase_09 AC 68 ms
63,488 KB
testcase_10 AC 81 ms
69,120 KB
testcase_11 AC 324 ms
100,992 KB
testcase_12 AC 287 ms
92,928 KB
testcase_13 AC 264 ms
106,624 KB
testcase_14 AC 263 ms
103,552 KB
testcase_15 AC 317 ms
106,752 KB
testcase_16 AC 311 ms
106,752 KB
testcase_17 AC 324 ms
107,008 KB
testcase_18 AC 324 ms
107,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


class SegTree:
    def __init__(self, N, func, e):
        self.N = N
        self.func = func
        self.X = [e] * (N << 1)
        self.e = e

    def build(self, seq):
        for i in range(self.N):
            self.X[self.N + i] = seq[i]
        for i in range(self.N)[::-1]:
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def add(self, i, x):
        i += self.N
        self.X[i] += x
        while i > 1:
            i >>= 1
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def update(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def query(self, L, R):
        L += self.N
        R += self.N
        vL = self.e
        vR = self.e
        while L < R:
            if L & 1:
                vL = self.func(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.func(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.func(vL, vR)


N, Q = map(int, input().split())
A = list(map(int, input().split()))
idx = {}
for i in range(N):
    idx[A[i]] = i + 1

st = SegTree(N, min, N + 1)
st.build(A)
for _ in range(Q):
    t, l, r = map(int, input().split())
    l -= 1
    r -= 1
    if t == 1:
        lv = st.X[N + l]
        rv = st.X[N + r]
        st.update(l, rv)
        st.update(r, lv)
        idx[lv], idx[rv] = idx[rv], idx[lv]
    else:
        mv = st.query(l, r + 1)
        print(idx[mv])
0