結果
問題 | No.875 Range Mindex Query |
ユーザー | hase_0o0 |
提出日時 | 2019-10-25 11:41:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 439 ms / 2,000 ms |
コード長 | 1,284 bytes |
コンパイル時間 | 371 ms |
コンパイル使用メモリ | 86,836 KB |
実行使用メモリ | 94,220 KB |
最終ジャッジ日時 | 2023-09-26 13:40:57 |
合計ジャッジ時間 | 6,455 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 96 ms
71,400 KB |
testcase_01 | AC | 119 ms
76,968 KB |
testcase_02 | AC | 128 ms
76,928 KB |
testcase_03 | AC | 103 ms
76,468 KB |
testcase_04 | AC | 111 ms
76,940 KB |
testcase_05 | AC | 109 ms
76,820 KB |
testcase_06 | AC | 120 ms
77,080 KB |
testcase_07 | AC | 120 ms
76,968 KB |
testcase_08 | AC | 112 ms
76,756 KB |
testcase_09 | AC | 111 ms
77,096 KB |
testcase_10 | AC | 129 ms
77,012 KB |
testcase_11 | AC | 436 ms
90,860 KB |
testcase_12 | AC | 395 ms
88,516 KB |
testcase_13 | AC | 386 ms
94,152 KB |
testcase_14 | AC | 386 ms
92,724 KB |
testcase_15 | AC | 439 ms
94,056 KB |
testcase_16 | AC | 384 ms
94,172 KB |
testcase_17 | AC | 405 ms
94,116 KB |
testcase_18 | AC | 419 ms
94,220 KB |
ソースコード
import sys input=sys.stdin.readline 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): #min(a[l:r)) L, R = l+self.n, r+self.n ide_ele = float("inf") res = ide_ele while L < R: if R & 1: R -= 1 res = min(res, self.arr[R-1]) if L & 1: res = min(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)