結果

問題 No.875 Range Mindex Query
ユーザー takakintakakin
提出日時 2020-04-21 21:48:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 771 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 33,672 KB
最終ジャッジ日時 2024-04-17 16:47:52
合計ジャッジ時間 12,983 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 41 ms
10,752 KB
testcase_02 AC 44 ms
10,752 KB
testcase_03 AC 34 ms
10,752 KB
testcase_04 AC 37 ms
10,752 KB
testcase_05 AC 38 ms
11,008 KB
testcase_06 AC 42 ms
11,008 KB
testcase_07 AC 40 ms
10,752 KB
testcase_08 AC 38 ms
10,880 KB
testcase_09 AC 36 ms
10,752 KB
testcase_10 AC 45 ms
10,880 KB
testcase_11 TLE -
testcase_12 AC 1,917 ms
20,764 KB
testcase_13 AC 1,978 ms
28,044 KB
testcase_14 AC 1,911 ms
24,076 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
権限があれば一括ダウンロードができます

ソースコード

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