結果

問題 No.875 Range Mindex Query
ユーザー kenta255kenta255
提出日時 2019-09-06 23:49:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 2,176 bytes
コンパイル時間 4,088 ms
コンパイル使用メモリ 205,152 KB
実行使用メモリ 5,308 KB
最終ジャッジ日時 2023-09-07 03:02:10
合計ジャッジ時間 6,324 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,384 KB
testcase_11 AC 197 ms
5,308 KB
testcase_12 AC 165 ms
4,380 KB
testcase_13 AC 140 ms
5,084 KB
testcase_14 AC 136 ms
5,228 KB
testcase_15 AC 191 ms
5,072 KB
testcase_16 AC 252 ms
5,076 KB
testcase_17 AC 288 ms
5,144 KB
testcase_18 AC 259 ms
5,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


class Seg_Tree{
public:
	vector< pair<int,int> > dat;
	// first  -> min value
	// second -> min index
	int n;
	void initsize(int n0){
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++){
					dat[i].first=INT_MAX;
					dat[i].second = i-n+1;
				}
				break;
			}
			k*=2;
		}
	}
	//i banme wo x nisuru
	void update(int i,int x){
		i += n-1;
		dat[i].first = x;
		while(i>0){
			i = (i-1) / 2;
			if(dat[i*2+1].first<=dat[i*2+2].first)
				dat[i] = dat[i*2+1];
			else
				dat[i] = dat[i*2+2];
		}
	}
	//[a,b)
	pair<int,int> query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return {INT_MAX,-1};
		if(a<=l && r<=b)return dat[k];
		else{
			pair<int,int> vl = query0(a,b,k*2+1,l,(l+r)/2);
			pair<int,int> vr = query0(a,b,k*2+2,(l+r)/2,r);
			if(vl.first<=vr.first)return vl;
			else return vr;
		}
	}
	//return min [a,b)
	pair<int,int> query(int a,int b){
		return query0(a,b,0,0,n);
	}
	int val(int i){
		i += n-1;
		return dat[i].first;
	}
};

int main(){
	int N,a,Q;
	cin >> N >> Q;
	Seg_Tree rmq;
	rmq.initsize(N+2);
	FOR(i,0,N){
		cin >> a;
		rmq.update(i+1,a);
	}
	FOR(i,0,Q){
		int q,l,r;
		cin >> q >> l >> r;
		if(q==1){
			int al = rmq.val(l);
			int ar = rmq.val(r);
			rmq.update(l,ar);
			rmq.update(r,al);
		}else{
			cout << rmq.query(l,r+1).second << endl;
		}
	}
}
0