結果

問題 No.875 Range Mindex Query
ユーザー takakintakakin
提出日時 2020-04-21 21:38:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 768 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 28,612 KB
最終ジャッジ日時 2024-04-17 16:28:45
合計ジャッジ時間 15,705 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
10,880 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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,r)]+1)
0