結果

問題 No.875 Range Mindex Query
ユーザー pockyny
提出日時 2019-09-06 21:40:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 74,876 KB
最終ジャッジ日時 2025-01-07 16:43:50
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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