結果
問題 | No.875 Range Mindex Query |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2022-06-25 15:32:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 535 ms / 2,000 ms |
コード長 | 1,677 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 82,608 KB |
実行使用メモリ | 92,800 KB |
最終ジャッジ日時 | 2024-04-26 22:09:17 |
合計ジャッジ時間 | 7,103 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
52,096 KB |
testcase_01 | AC | 98 ms
66,304 KB |
testcase_02 | AC | 83 ms
70,400 KB |
testcase_03 | AC | 51 ms
59,648 KB |
testcase_04 | AC | 60 ms
61,696 KB |
testcase_05 | AC | 46 ms
54,144 KB |
testcase_06 | AC | 65 ms
65,024 KB |
testcase_07 | AC | 71 ms
67,456 KB |
testcase_08 | AC | 56 ms
62,720 KB |
testcase_09 | AC | 56 ms
62,848 KB |
testcase_10 | AC | 76 ms
70,144 KB |
testcase_11 | AC | 504 ms
89,344 KB |
testcase_12 | AC | 464 ms
84,408 KB |
testcase_13 | AC | 423 ms
92,288 KB |
testcase_14 | AC | 428 ms
90,752 KB |
testcase_15 | AC | 484 ms
92,800 KB |
testcase_16 | AC | 520 ms
92,160 KB |
testcase_17 | AC | 530 ms
92,544 KB |
testcase_18 | AC | 535 ms
92,544 KB |
ソースコード
class SegTree: """ define what you want to do with 0 index, ex) size = tree_size, func = min or max, sta = default_value """ def __init__(self,size,func,sta): self.n = size self.size = 1 << size.bit_length() self.func = func self.sta = sta self.tree = [sta]*(2*self.size) def build(self, list): """ set list and update tree""" for i,x in enumerate(list,self.size): self.tree[i] = x for i in range(self.size-1,0,-1): self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1]) def set(self,i,x): i += self.size self.tree[i] = x while i > 1: i >>= 1 self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1]) def get(self,l,r): """ take the value of [l r) with func (min or max)""" l += self.size r += self.size res = self.sta while l < r: if l & 1: res = self.func(self.tree[l],res) l += 1 if r & 1: res = self.func(self.tree[r-1],res) l >>= 1 r >>= 1 return res n,q = map(int,input().split()) A = list(map(int,input().split())) idx = [0]*(n+1) for i,a in enumerate(A): idx[a] = i seg = SegTree(n,min,10**10) seg.build(A) for _ in range(q): t,l,r = map(int,input().split()) if t == 1: l,r = l-1,r-1 al,ar = A[l],A[r] idx[al],idx[ar] = idx[ar],idx[al] A[l],A[r] = A[r],A[l] seg.set(l,ar) seg.set(r,al) else: l -= 1 ma = seg.get(l,r) print(idx[ma]+1)