結果

問題 No.875 Range Mindex Query
ユーザー chocopuuchocopuu
提出日時 2019-09-06 22:38:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 172,056 KB
実行使用メモリ 5,668 KB
最終ジャッジ日時 2023-09-07 01:31:46
合計ジャッジ時間 5,287 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 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,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,376 KB
testcase_11 AC 255 ms
4,828 KB
testcase_12 AC 212 ms
4,540 KB
testcase_13 AC 173 ms
4,836 KB
testcase_14 AC 170 ms
4,788 KB
testcase_15 AC 238 ms
5,356 KB
testcase_16 AC 327 ms
5,500 KB
testcase_17 AC 353 ms
5,668 KB
testcase_18 AC 338 ms
5,504 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;}

constexpr int B = 340;

signed main(){
	int N,Q;
	cin >> N >> Q;
	vector<pair<int,int>>a(N);
	vector<pair<int,int>>seg(N/B+1,{INF,INF});
	vector<int>ans;
	REP(i,N){
		int t;
		cin >> t;
		a[i] = {t,i};
	}
	REP(i,N){
		if(seg[i/B].first > a[i].first)seg[i/B] = a[i];
	}
	while(Q--){
		int x,l,r;
		cin >> x >> l >> r;
		x--;
		if(x){
			l--;
			int mi = INF,id = -1;
			FOR(i,l,r){
				int bi = i / B;
				if(l <= bi * B && (bi + 1) * B <= r){
					if(CHMIN(mi,seg[bi].first))id = seg[bi].second;
					i += B - 1;
				}else{
					if(CHMIN(mi,a[i].first))id = a[i].second;
				}
			}
			ans.push_back(id+1);
		}else{
			l--;r--;
			swap(a[l].first,a[r].first);
			int ll = l / B;
			seg[ll] = {INF,INF};
			REP(i,B){
				if(ll*B+i >= N)break;
				if(seg[ll].first > a[ll*B+i].first)seg[ll] = a[ll*B+i];
			}
			int rr = r / B;
			seg[rr] = {INF,INF};
			REP(i,B){
				if(rr*B+i >= N)break;
				if(seg[rr].first > a[rr*B+i].first)seg[rr] = a[rr*B+i];
			}
		}
	}
	for(auto e:ans){
		cout << e << endl;
	}
}
0