結果

問題 No.875 Range Mindex Query
ユーザー simamumusimamumu
提出日時 2019-09-06 22:22:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,165 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,628 KB
実行使用メモリ 181,824 KB
最終ジャッジ日時 2023-09-07 00:58:55
合計ジャッジ時間 7,760 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 193 ms
85,980 KB
testcase_01 AC 312 ms
86,168 KB
testcase_02 AC 336 ms
85,012 KB
testcase_03 AC 233 ms
83,012 KB
testcase_04 AC 268 ms
84,224 KB
testcase_05 AC 260 ms
84,712 KB
testcase_06 AC 325 ms
87,152 KB
testcase_07 AC 296 ms
85,252 KB
testcase_08 AC 297 ms
85,980 KB
testcase_09 AC 269 ms
84,160 KB
testcase_10 AC 369 ms
87,952 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

class Node:
    def __init__(self,value,index):
        self.value = value
        self.index = index

    def items(self):
        return [self.value,self.index]

class SegmentTree:
    def __init__(self,N,aa):
        self.N0 = 2**(N-1).bit_length()
        self.nodes = [Node(INF,i+1-self.N0) for i in range(2*self.N0-1)]
        for i in reversed(range(2*self.N0-1)):
            ind = i+1-self.N0
            if ind >= N:
                self.nodes[i].value = INF
            elif N > ind >= 0:
                self.nodes[i].value = aa[ind]
            else:
                self.nodes[i] = copy.copy(self.process(self.nodes[i*2+1],self.nodes[i*2+2]))

    def update(self,i,x): #iの値をxに更新
        i += self.N0 - 1
        self.nodes[i].value = x
        while i > 0:
            i = (i-1)//2
            self.nodes[i] = copy.copy(self.process(self.nodes[i*2+1],self.nodes[i*2+2]))

    def query(self,L,R): #[L,R)の値
        ans = Node(INF,INF)
        L += self.N0
        R += self.N0
        while L < R:
            if R&1 :
                R -= 1
                ans = copy.copy(self.process(ans,self.nodes[R-1]))
            if L&1 :
                ans = copy.copy(self.process(ans,self.nodes[L-1]))
                L += 1
            L >>= 1; R >>= 1
        return ans

    def process(self,node_x,node_y): #x,yが子の時,親に返る値
        if node_x.value < node_y.value:
            return node_x
        else:
            return node_y

N,Q = inpl()
aa = inpl()

ST = SegmentTree(N,aa)

for _ in range(Q):
    #print([node.items() for node in ST.nodes])
    q,L,R = inpl()
    L,R = L-1, R-1
    if q == 1:
        l = ST.nodes[L+ST.N0-1].value
        r = ST.nodes[R+ST.N0-1].value
        ST.update(L,r)
        ST.update(R,l)
    else:
        print(ST.query(L,R+1).index+1)
0