結果

問題 No.875 Range Mindex Query
ユーザー simamumusimamumu
提出日時 2019-09-06 21:48:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,919 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 11,080 KB
実行使用メモリ 14,768 KB
最終ジャッジ日時 2023-09-06 23:33:47
合計ジャッジ時間 4,994 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
14,768 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 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,d):
        self.NN = 1
        while self.NN < N:
            self.NN *= 2
        self.nodes = [Node(d,i+1-self.NN) for i in range(self.NN*2-1)]

    def update(self,i,x): #iの値をxに更新
        i += self.NN - 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)の値
        N = (self.NN+1)//2
        ans = Node(INF,INF)
        L += N-1
        R += N-1
        while L < R:
            if (L&1) == 0:
                ans = copy.copy(self.process(ans,self.nodes[L]))
            if (R&1) == 0:
                ans = copy.copy(self.process(ans,self.nodes[L]))
            L = L // 2;
            R = (R - 1) // 2;
        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+1,INF)

for i,a in enumerate(aa):
    ST.update(i,a)



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.NN-1].value
        r = ST.nodes[R+ST.NN-1].value
        ST.update(L,r)
        ST.update(R,l)
    else:
        print(ST.query(L,R+1).index+1)
0