結果
問題 | No.875 Range Mindex Query |
ユーザー | hase_0o0 |
提出日時 | 2019-10-25 11:45:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 438 ms / 2,000 ms |
コード長 | 1,498 bytes |
コンパイル時間 | 797 ms |
コンパイル使用メモリ | 87,352 KB |
実行使用メモリ | 94,484 KB |
最終ジャッジ日時 | 2023-09-26 13:48:04 |
合計ジャッジ時間 | 6,907 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 92 ms
71,688 KB |
testcase_01 | AC | 118 ms
77,524 KB |
testcase_02 | AC | 123 ms
77,460 KB |
testcase_03 | AC | 102 ms
76,732 KB |
testcase_04 | AC | 108 ms
77,304 KB |
testcase_05 | AC | 108 ms
76,604 KB |
testcase_06 | AC | 121 ms
77,484 KB |
testcase_07 | AC | 120 ms
77,412 KB |
testcase_08 | AC | 109 ms
77,000 KB |
testcase_09 | AC | 111 ms
77,476 KB |
testcase_10 | AC | 129 ms
77,624 KB |
testcase_11 | AC | 438 ms
91,412 KB |
testcase_12 | AC | 406 ms
88,564 KB |
testcase_13 | AC | 399 ms
94,332 KB |
testcase_14 | AC | 396 ms
92,848 KB |
testcase_15 | AC | 436 ms
94,448 KB |
testcase_16 | AC | 381 ms
94,484 KB |
testcase_17 | AC | 406 ms
94,296 KB |
testcase_18 | AC | 403 ms
94,444 KB |
ソースコード
import sys input=sys.stdin.readline def func(x,y): return min(x,y) class SegmentTree: def __init__(self, n): #a1, a2, ..., an n_ = 1 while n_ < n: n_ *= 2 self.n = n_ self.arr = [10**18] * (2*self.n-1) def update(self, k, a): #0_indexed k += self.n - 1 self.arr[k] = a while k > 0: k = (k-1) // 2 self.arr[k] = min(self.arr[2*k+1], self.arr[2*k+2]) def query(self, l, r): L, R = l+self.n, r+self.n ide_ele = float("inf") #単位元(ide_ele)は、区間外の値などに設定する値です。 #ex) 最小値のセグ木 → +inf # 和のセグ木 → 0 # 積のセグ木 → 1 # gcdのセグ木 → 0 res = ide_ele while L < R: if R & 1: R -= 1 res = func(res, self.arr[R-1]) # if L & 1: res = func(res, self.arr[L-1]) L += 1 L >>= 1 R >>= 1 return res from collections import defaultdict n,q=map(int,input().split()) a=list(map(int,input().split())) st=SegmentTree(n) idx=defaultdict(int) for i in range(n): st.update(i,a[i]) idx[a[i]]=i for _ in range(q): i,l,r=map(int,input().split()) if i==1: st.update(l-1,a[r-1]) st.update(r-1,a[l-1]) idx[a[r-1]]=l-1 idx[a[l-1]]=r-1 a[l-1],a[r-1]=a[r-1],a[l-1] else: x=st.query(l-1,r) print(idx[x]+1)