結果

問題 No.875 Range Mindex Query
ユーザー pockynypockyny
提出日時 2019-09-06 21:40:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 76,684 KB
実行使用メモリ 6,500 KB
最終ジャッジ日時 2023-09-06 23:15:38
合計ジャッジ時間 3,496 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 196 ms
5,896 KB
testcase_12 AC 161 ms
5,256 KB
testcase_13 AC 135 ms
6,424 KB
testcase_14 AC 134 ms
6,080 KB
testcase_15 AC 182 ms
6,500 KB
testcase_16 AC 247 ms
6,360 KB
testcase_17 AC 267 ms
6,400 KB
testcase_18 AC 259 ms
6,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;
ll n,mx = 100000000000000;
pair<ll,ll> t[200010];
void built(){
	for(int i = n-1;i>0;i--){
		t[i] = min(t[i<<1],t[i<<1|1]);
	}
}

void update(ll p,ll a){
	for(t[p+=n].first = a;p>1;p >>= 1){
		t[p>>1] = min(t[p],t[p^1]);
	}
}

pair<ll,ll> query(int l, int r){
	pair<ll,ll> mn = {mx,-1};
	for(l += n, r += n; l<r; l >>= 1,r >>= 1){
		if(l&1) mn = min(mn,t[l++]);
		if(r&1) mn = min(mn,t[--r]);
	}
	return mn;
}

int main(){
	int i,q;
	cin >> n >> q;
	for(i=0;i<n;i++){
		int a; cin >> a;
		t[i + n] = {a,i + 1};
	}
	built();
	for(i=0;i<q;i++){
		int a,b,c;
		cin >> a >> b >> c;
		b--; c--;
		if(a==1){
			int x = t[b + n].first,y = t[c + n].first;
			update(c,x); update(b,y);
		}else{
			cout << query(b,c + 1).second << endl;
		}
	}
}
0