結果

問題 No.875 Range Mindex Query
ユーザー takakintakakin
提出日時 2020-04-21 21:49:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 89,024 KB
最終ジャッジ日時 2024-04-17 16:48:34
合計ジャッジ時間 4,621 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,096 KB
testcase_01 AC 70 ms
66,432 KB
testcase_02 AC 79 ms
70,016 KB
testcase_03 AC 50 ms
58,880 KB
testcase_04 AC 60 ms
63,360 KB
testcase_05 AC 56 ms
61,312 KB
testcase_06 AC 69 ms
66,304 KB
testcase_07 AC 69 ms
66,048 KB
testcase_08 AC 62 ms
63,744 KB
testcase_09 AC 63 ms
64,384 KB
testcase_10 AC 78 ms
69,760 KB
testcase_11 AC 343 ms
87,168 KB
testcase_12 AC 308 ms
84,616 KB
testcase_13 AC 312 ms
88,388 KB
testcase_14 AC 314 ms
88,488 KB
testcase_15 AC 365 ms
89,024 KB
testcase_16 AC 327 ms
88,668 KB
testcase_17 AC 354 ms
88,680 KB
testcase_18 AC 330 ms
88,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n,q=map(int,input().split())
A=[int(i) for i in input().split()]

n0=2**(n-1).bit_length()
INF=2**31-1
data=[INF]*(2*n0)
# a_k の値を x に更新
def update(k,x):
  k+=n0-1
  data[k]=x
  while k>=0:
    k=(k-1)//2
    data[k]=min(data[2*k+1],data[2*k+2])
# 区間[l, r)の最小値
def query(l,r):
  L=l+n0;R=r+n0
  s=INF
  while L<R:
    if R&1:
      R-=1
      s=min(s,data[R-1])

    if L&1:
      s=min(s,data[L-1])
      L+=1
    L>>=1;R>>=1
  return s
D=dict()
for i,a in enumerate(A):
  D[a]=i
  update(i,a)

for _ in range(q):
  x,l,r=map(int,input().split())
  if x==1:
    a,b=data[l-1+n0-1],data[r-1+n0-1]
    D[a],D[b]=r-1,l-1
    update(l-1,b)
    update(r-1,a)
  else:
    print(D[query(l-1,r)]+1)
0