結果
問題 | No.875 Range Mindex Query |
ユーザー | hase_0o0 |
提出日時 | 2019-11-21 00:35:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 521 ms / 2,000 ms |
コード長 | 1,520 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 95,628 KB |
最終ジャッジ日時 | 2024-04-16 21:21:59 |
合計ジャッジ時間 | 6,537 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,760 KB |
testcase_01 | AC | 70 ms
72,576 KB |
testcase_02 | AC | 80 ms
76,324 KB |
testcase_03 | AC | 46 ms
61,696 KB |
testcase_04 | AC | 62 ms
68,352 KB |
testcase_05 | AC | 51 ms
64,896 KB |
testcase_06 | AC | 68 ms
72,320 KB |
testcase_07 | AC | 76 ms
73,236 KB |
testcase_08 | AC | 58 ms
67,840 KB |
testcase_09 | AC | 57 ms
67,584 KB |
testcase_10 | AC | 85 ms
76,448 KB |
testcase_11 | AC | 521 ms
87,936 KB |
testcase_12 | AC | 465 ms
87,016 KB |
testcase_13 | AC | 456 ms
95,428 KB |
testcase_14 | AC | 446 ms
93,776 KB |
testcase_15 | AC | 494 ms
95,388 KB |
testcase_16 | AC | 507 ms
95,628 KB |
testcase_17 | AC | 515 ms
95,580 KB |
testcase_18 | AC | 510 ms
95,484 KB |
ソースコード
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**6] * (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] = func(self.arr[2*k+1], self.arr[2*k+2]) def query(self, l, r):#[l,r)の値を返す L, R = l+self.n, r+self.n ide_ele = 10**6 #単位元(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 n,q=map(int,input().split()) a=list(map(int,input().split())) sg=SegmentTree(n) for i in range(1,n+1): sg.update(i,a[i-1]) from collections import defaultdict d=defaultdict(int) for i in range(n): d[a[i]]=i+1 for _ in range(q): k,l,r=map(int,input().split()) if k==1: sg.update(l,a[r-1]) sg.update(r,a[l-1]) d[a[l-1]],d[a[r-1]]=d[a[r-1]],d[a[l-1]] a[l-1],a[r-1]=a[r-1],a[l-1] else: print(d[sg.query(l,r+1)])