結果

問題 No.875 Range Mindex Query
ユーザー chocopuuchocopuu
提出日時 2019-09-07 03:00:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 1,974 bytes
コンパイル時間 1,440 ms
コンパイル使用メモリ 175,044 KB
実行使用メモリ 8,324 KB
最終ジャッジ日時 2023-09-07 08:21:42
合計ジャッジ時間 4,273 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 180 ms
7,704 KB
testcase_12 AC 144 ms
5,716 KB
testcase_13 AC 132 ms
7,528 KB
testcase_14 AC 155 ms
7,444 KB
testcase_15 AC 174 ms
7,908 KB
testcase_16 AC 218 ms
8,248 KB
testcase_17 AC 235 ms
8,320 KB
testcase_18 AC 247 ms
8,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

template<class T>
class SegmentTree{
	private:
	int N;
	T initVal;
	std::vector<T>ary;
	std::function<T(T&,T&)>merge;
	void init(int n){
		while(N < n)N <<= 1;
		ary.resize(N << 1,initVal);
	}
	public:
		SegmentTree(int n,T initVal,std::function<T(T&,T&)>f):
			N(1),initVal(initVal),merge(f){init(n);}
	// -- a[i] = val;
	inline void update(int i,T val){
		ary[i += N] = val;
		while(i > 1){
			i >>= 1;
			ary[i] = merge(ary[i << 1],ary[(i << 1) + 1]);
		}
	}
	// -- a[i] += val;
	inline void add(int i,T val){
		update(i,ary[i + N] + val);
	}
	// -- [l,r)
	inline T query(int l,int r){
		if(l >= r)return initVal;
		T vr = initVal,vl = initVal;
		for(l += N,r += N;l != r;l >>= 1,r >>= 1){
			if(l & 1)vl = merge(vl,ary[l++]);
			if(r & 1)vr = merge(vr,ary[--r]);
		}
		return merge(vl,vr);
	}
	/*
	void debug show(){
		for(iint i = N;i < N;i++)std::cerr << ary[i] << ' ';
		std:::cerr << '\n';
	}
	*/
};

signed main(){
	int N,Q;
	cin >> N >> Q;
	vector<int>ans;
	auto seg = SegmentTree<pair<int,int>>(N,make_pair(INF,INF),[](pair<int,int>&l,pair<int,int>&r){return min(l,r);});
	REP(i,N){
		int t;cin >> t;
		seg.update(i,{t,i});
	}
	while(Q--){
		int x;
		cin >> x;
		if(x == 2){
			int l,r;
			cin >> l >> r;
			ans.push_back(seg.query(l-1,r).second+1);
		}else{
			int l,r;
			cin >> l >> r;
			l--;r--;
			int ll = seg.query(l,l+1).first;
			int rr = seg.query(r,r+1).first;
			seg.update(l,{rr,l});
			seg.update(r,{ll,r});
		}
	}
	for(auto e:ans){
		cout << e << endl;
	}
}
0