結果
問題 | No.875 Range Mindex Query |
ユーザー | titia |
提出日時 | 2019-09-06 21:54:24 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,379 ms / 2,000 ms |
コード長 | 1,381 bytes |
コンパイル時間 | 98 ms |
コンパイル使用メモリ | 10,984 KB |
実行使用メモリ | 37,576 KB |
最終ジャッジ日時 | 2023-09-06 23:40:42 |
合計ジャッジ時間 | 10,395 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,368 KB |
testcase_01 | AC | 21 ms
8,436 KB |
testcase_02 | AC | 23 ms
8,064 KB |
testcase_03 | AC | 16 ms
8,404 KB |
testcase_04 | AC | 18 ms
8,308 KB |
testcase_05 | AC | 18 ms
8,208 KB |
testcase_06 | AC | 19 ms
8,252 KB |
testcase_07 | AC | 21 ms
8,308 KB |
testcase_08 | AC | 19 ms
8,460 KB |
testcase_09 | AC | 18 ms
8,280 KB |
testcase_10 | AC | 23 ms
8,608 KB |
testcase_11 | AC | 1,379 ms
35,852 KB |
testcase_12 | AC | 1,074 ms
30,320 KB |
testcase_13 | AC | 938 ms
29,764 KB |
testcase_14 | AC | 927 ms
29,408 KB |
testcase_15 | AC | 1,298 ms
35,348 KB |
testcase_16 | AC | 1,039 ms
35,696 KB |
testcase_17 | AC | 1,108 ms
37,576 KB |
testcase_18 | AC | 1,087 ms
36,728 KB |
ソースコード
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)