結果

問題 No.875 Range Mindex Query
ユーザー sigma425sigma425
提出日時 2019-09-08 17:28:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,945 bytes
コンパイル時間 1,338 ms
コンパイル使用メモリ 151,024 KB
実行使用メモリ 5,428 KB
最終ジャッジ日時 2023-09-09 22:34:13
合計ジャッジ時間 3,824 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 129 ms
5,356 KB
testcase_12 AC 107 ms
4,384 KB
testcase_13 AC 85 ms
5,408 KB
testcase_14 AC 85 ms
5,428 KB
testcase_15 AC 122 ms
5,352 KB
testcase_16 AC 179 ms
5,376 KB
testcase_17 AC 191 ms
5,388 KB
testcase_18 AC 187 ms
5,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

struct segtree{
	using D = int;
	D inf = 1e9;
	using P = pair<D,int>;

	int N;
	vector<P> val;
	
	segtree(){}
	segtree(const vector<D>& ds){
		int n = ds.size();
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,P(inf,-1));
		rep(i,n) val[i+N] = P(ds[i],i);
		for(int i=N-1;i>0;i--) val[i] = min(val[i*2],val[i*2+1]);
	}
	void assign(int k,D d){
		k+=N;
		val[k]=P(d,k-N);
		k/=2;
		while(k){
			val[k] = min(val[k*2],val[k*2+1]);
			k/=2;
		}
	}
	P getmina(int a,int b){	//P(min,leftmost argmin)
		P res = P(inf,-1);
		a+=N,b+=N;
		while(a<b){
			if(a&1) chmin(res,val[a++]);
			if(b&1) chmin(res,val[--b]);
			a/=2,b/=2;
		}
		return res;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,Q;
	cin >> N >> Q;
	V<int> a(N);
	rep(i,N) cin >> a[i];
	segtree seg(a);
	rep(_,Q){
		int t;
		cin >> t;
		if(t == 1){
			int l,r;
			cin >> l >> r;
			l--,r--;
			swap(a[l],a[r]);
			seg.assign(l,a[l]);
			seg.assign(r,a[r]);
		}else{
			int l,r;
			cin >> l >> r;
			l--;
			cout << seg.getmina(l,r).sc + 1 << endl;
		}
	}
}
0