結果

問題 No.875 Range Mindex Query
ユーザー tkmst201tkmst201
提出日時 2019-09-06 21:41:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 1,765 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 162,480 KB
実行使用メモリ 5,444 KB
最終ジャッジ日時 2023-09-06 23:16:29
合計ジャッジ時間 4,579 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 4 ms
4,380 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 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 232 ms
5,108 KB
testcase_12 AC 190 ms
4,380 KB
testcase_13 AC 157 ms
5,104 KB
testcase_14 AC 162 ms
5,224 KB
testcase_15 AC 217 ms
5,152 KB
testcase_16 AC 266 ms
5,444 KB
testcase_17 AC 287 ms
5,276 KB
testcase_18 AC 275 ms
5,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

struct SegTree {
	pii init_val;
	int n;
	vector<pii> dat;
	
	SegTree(int _n, pii init_val) : init_val(init_val) {
		n = 1;
		while (n < _n) n *= 2;
		dat.resize(n * 2 - 1, init_val);
	}
	
	void update(int i, pii x) {
		i += n - 1;
		dat[i] = min(dat[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	
	void set(int i, pii x) {
		x.se = i;
		dat[i + n - 1] = x;
		update(i, x);
	}
	
	// 探索範囲[a,b), 現在見ているkノード[l,r)
	pii query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return min( query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r) );
	}
};

int N, Q;

int main() {
	cin >> N >> Q;
	
	SegTree seg(N, pii(INF, INF));
	REP(i, N) {
		int a;
		scanf("%d", &a);
		seg.set(i, pii(a, i));
	}
	
	REP(i, Q) {
		int q, l, r;
		cin >> q >> l >> r;
		l--; r--;
		if (q == 1) {
			pii tmp = seg.query(r, r + 1);
			seg.set(r, seg.query(l, l + 1));
			seg.set(l, tmp);
		}
		else {
			cout << seg.query(l, r + 1).se + 1 << endl;
		}
	}
	
	return 0;
}
0