結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2020-09-03 14:16:37 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 475 ms / 2,000 ms |
| コード長 | 1,270 bytes |
| コンパイル時間 | 613 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 91,392 KB |
| 最終ジャッジ日時 | 2024-11-23 17:22:47 |
| 合計ジャッジ時間 | 7,239 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#0-indexed , 半開区間[a,b)
#calc変更で演算変更
class SegTree:
def __init__(self,N,first):
self.NO = 2**(N-1).bit_length()
self.First = first
self.data = [first] * (2*self.NO)
def calc(self,l,r):
return min(l,r)
def update(self,ind,x):
ind += self.NO - 1
self.data[ind] = x
while ind >= 0:
ind = (ind - 1)//2
self.data[ind] = self.calc(self.data[2*ind+1],self.data[2*ind+2])
def query(self,l,r):
L = l + self.NO
R = r + self.NO
s = self.First
while L < R:
if R & 1:
R -= 1
s = self.calc(s , self.data[R-1])
if L & 1:
s = self.calc(s , self.data[L-1])
L += 1
L >>= 1
R >>= 1
return s
from sys import stdin
N,Q = map(int,stdin.readline().split())
a = list(map(int,stdin.readline().split()))
T = SegTree(N,(float("inf"),-1))
for i in range(N):
T.update(i,(a[i],i))
for i in range(Q):
s,l,r = map(int,stdin.readline().split())
l -= 1
r -= 1
if s == 1:
a[l],a[r] = a[r],a[l]
T.update(l,(a[l],l))
T.update(r,(a[r],r))
else:
print(T.query(l,r+1)[1] + 1)
SPD_9X2