結果
問題 | No.875 Range Mindex Query |
ユーザー | mkawa2 |
提出日時 | 2021-03-18 16:50:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 368 ms / 2,000 ms |
コード長 | 3,943 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 94,848 KB |
最終ジャッジ日時 | 2024-11-16 20:08:48 |
合計ジャッジ時間 | 5,980 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,736 KB |
testcase_01 | AC | 81 ms
70,784 KB |
testcase_02 | AC | 101 ms
76,544 KB |
testcase_03 | AC | 54 ms
61,568 KB |
testcase_04 | AC | 68 ms
66,560 KB |
testcase_05 | AC | 49 ms
60,032 KB |
testcase_06 | AC | 79 ms
70,400 KB |
testcase_07 | AC | 89 ms
73,216 KB |
testcase_08 | AC | 68 ms
66,688 KB |
testcase_09 | AC | 73 ms
67,072 KB |
testcase_10 | AC | 91 ms
74,624 KB |
testcase_11 | AC | 311 ms
91,392 KB |
testcase_12 | AC | 261 ms
85,248 KB |
testcase_13 | AC | 253 ms
94,592 KB |
testcase_14 | AC | 273 ms
92,928 KB |
testcase_15 | AC | 303 ms
94,208 KB |
testcase_16 | AC | 332 ms
94,208 KB |
testcase_17 | AC | 368 ms
94,848 KB |
testcase_18 | AC | 359 ms
94,592 KB |
ソースコード
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 md = 998244353 # md = 10**9+7 class SegtreeMin(): def __init__(self, n): self.inf = 10**16 aa = [] if not isinstance(n, int): aa = n n = len(aa) self.tree_width = tw = 1 << (n-1).bit_length() self.tree = [self.inf]*(tw*2-1) self.idx = [self.inf]*(tw*2-1) if aa: self.tree[tw-1:tw-1+len(aa)] = aa self.idx[tw-1:tw-1+len(aa)] = list(range(n)) for i in range(tw-2, -1, -1): if self.tree[i*2+1] < self.tree[i*2+2]: self.tree[i] = self.tree[i*2+1] self.idx[i] = self.idx[i*2+1] else: self.tree[i] = self.tree[i*2+2] self.idx[i] = self.idx[i*2+2] def update(self, i, a): seg_i = self.tree_width-1+i self.tree[seg_i] = a while seg_i != 0: seg_i = (seg_i-1)//2 if self.tree[seg_i*2+1] < self.tree[seg_i*2+2]: self.tree[seg_i] = self.tree[seg_i*2+1] self.idx[seg_i] = self.idx[seg_i*2+1] else: self.tree[seg_i] = self.tree[seg_i*2+2] self.idx[seg_i] = self.idx[seg_i*2+2] def __getitem__(self, item): return self.tree[self.tree_width-1+item] def element(self, i): return self.tree[self.tree_width-1+i] # [l,r)の最小値 def min(self, l, r): res = self.inf resi=0 stack = [(0, 0, self.tree_width)] while stack: seg_i, segL, segR = stack.pop() if l <= segL and segR <= r: if self.tree[seg_i] < res: res = self.tree[seg_i] resi=self.idx[seg_i] else: segM = (segL+segR)//2 if r > segL and segM > l: stack.append((seg_i*2+1, segL, segM)) if r > segM and segR > l: stack.append((seg_i*2+2, segM, segR)) return resi,res # [l,r)でaより小さい要素のうち最右のインデックス def LessR(self, l, r, a): stack = [(0, 0, self.tree_width)] while stack: u, ul, ur = stack.pop() if ur-ul == 1: return u-self.tree_width+1 um = (ul+ur)//2 if self.tree[u*2+1] < a and ul < r and l < um: stack.append((u*2+1, ul, um)) if self.tree[u*2+2] < a and um < r and l < ur: stack.append((u*2+2, um, ur)) return -1 # [l,r)でaより小さい要素のうち最左のインデックス def LessL(self, l, r, a): stack = [(0, 0, self.tree_width)] while stack: u, ul, ur = stack.pop() if ur-ul == 1: return u-self.tree_width+1 um = (ul+ur)//2 if self.tree[u*2+2] < a and um < r and l < ur: stack.append((u*2+2, um, ur)) if self.tree[u*2+1] < a and ul < r and l < um: stack.append((u*2+1, ul, um)) return -1 n,q=LI() aa=LI() st=SegtreeMin(aa) for _ in range(q): t,l,r=LI1() if t==0: a=st[l] b=st[r] st.update(l,b) st.update(r,a) else: ans,_=st.min(l,r+1) print(ans+1)