結果

問題 No.875 Range Mindex Query
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2019-09-06 23:35:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 1,371 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 172,228 KB
実行使用メモリ 5,288 KB
最終ジャッジ日時 2023-09-07 02:45:36
合計ジャッジ時間 5,085 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 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,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 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 209 ms
5,084 KB
testcase_12 AC 171 ms
4,380 KB
testcase_13 AC 150 ms
5,144 KB
testcase_14 AC 146 ms
5,104 KB
testcase_15 AC 200 ms
5,288 KB
testcase_16 AC 258 ms
5,036 KB
testcase_17 AC 280 ms
5,076 KB
testcase_18 AC 267 ms
5,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	const T init;
	const F f;
	int sz;
	vector<T> seg;
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

int main() {
	int n, q; cin >> n >> q;
	SegmentTree<pair<int, int>> seg(n, {1e9, -1}, [](pair<int, int> lhs, pair<int, int> rhs){return min(lhs, rhs);});
	for(int i = 0; i < n; ++i) {
		int a; cin >> a;
		seg.replace(i, {a, i + 1});
	}
	while(q--) {
		int i; cin >> i;
		int l, r; cin >> l >> r;
		--l, --r;
		if(i == 1) {
			int ll = seg.get(l, l + 1).first;
			int rr = seg.get(r, r + 1).first;
			seg.replace(l, {rr, l + 1});
			seg.replace(r, {ll, r + 1});
		}
		if(i == 2) {
			cout << seg.get(l, r + 1).second << '\n';
		}
	}
	return 0;
}
0