結果

問題 No.875 Range Mindex Query
ユーザー titiatitia
提出日時 2019-09-06 21:59:36
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,380 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 93,536 KB
最終ジャッジ日時 2023-09-06 23:51:15
合計ジャッジ時間 4,965 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,476 KB
testcase_01 AC 81 ms
76,732 KB
testcase_02 AC 92 ms
76,720 KB
testcase_03 AC 70 ms
75,536 KB
testcase_04 AC 76 ms
76,676 KB
testcase_05 AC 72 ms
75,836 KB
testcase_06 AC 83 ms
76,612 KB
testcase_07 AC 84 ms
76,708 KB
testcase_08 AC 78 ms
76,664 KB
testcase_09 AC 78 ms
76,628 KB
testcase_10 AC 88 ms
76,668 KB
testcase_11 AC 314 ms
93,280 KB
testcase_12 AC 297 ms
90,800 KB
testcase_13 AC 274 ms
90,744 KB
testcase_14 AC 281 ms
89,584 KB
testcase_15 AC 312 ms
92,484 KB
testcase_16 AC 303 ms
92,724 KB
testcase_17 AC 320 ms
93,400 KB
testcase_18 AC 307 ms
93,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
A=list(map(int,input().split()))
Query=[list(map(int,input().split())) for i in range(Q)]

# Segment tree(1-indexed,再帰を使わないもの,最小値を求める)

seg_el=1<<(N.bit_length())# Segment treeの台の要素数
SEG=[1<<30]*(2*seg_el)# 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

for i in range(N):# Aを対応する箇所へupdate
    SEG[i+seg_el]=A[i]

for i in range(seg_el-1,0,-1):# 親の部分もupdate
    SEG[i]=min(SEG[i*2],SEG[i*2+1])

def update(n,x,seg_el):# A[n]をxへ更新(反映)
    i=n+seg_el
    SEG[i]=x
    i>>=1# 子ノードへ
    
    while i!=0:
        SEG[i]=min(SEG[i*2],SEG[i*2+1])
        i>>=1
        
def getvalues(l,r):# 区間[l,r)に関するminを調べる
    L=l+seg_el
    R=r+seg_el
    ANS=1<<30

    while L<R:
        if L & 1:
            ANS=min(ANS , SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS=min(ANS , SEG[R])
        L>>=1
        R>>=1

    return ANS

SC_IND=[-1]*(N+1)
for i,x in enumerate(A):
    SC_IND[x]=i


for q,x,y in Query:
    if q==1:
        x0,y0=SEG[seg_el+x-1],SEG[seg_el+y-1]
        update(x-1,y0,seg_el)
        update(y-1,x0,seg_el)
        SC_IND[x0],SC_IND[y0]=SC_IND[y0],SC_IND[x0]
    else:
        print(SC_IND[getvalues(x-1,y)]+1)


        
    
0