結果

問題 No.875 Range Mindex Query
ユーザー startcppstartcpp
提出日時 2019-09-06 21:29:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 1,187 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 68,152 KB
実行使用メモリ 5,856 KB
最終ジャッジ日時 2023-09-06 22:35:16
合計ジャッジ時間 3,561 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,400 KB
testcase_01 AC 5 ms
5,352 KB
testcase_02 AC 5 ms
5,484 KB
testcase_03 AC 4 ms
5,484 KB
testcase_04 AC 4 ms
5,640 KB
testcase_05 AC 4 ms
5,412 KB
testcase_06 AC 5 ms
5,552 KB
testcase_07 AC 4 ms
5,448 KB
testcase_08 AC 4 ms
5,420 KB
testcase_09 AC 4 ms
5,440 KB
testcase_10 AC 5 ms
5,368 KB
testcase_11 AC 210 ms
5,740 KB
testcase_12 AC 173 ms
5,604 KB
testcase_13 AC 150 ms
5,728 KB
testcase_14 AC 150 ms
5,700 KB
testcase_15 AC 198 ms
5,856 KB
testcase_16 AC 270 ms
5,728 KB
testcase_17 AC 297 ms
5,756 KB
testcase_18 AC 281 ms
5,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(i = 0; i < (n); i++)
using namespace std;
typedef pair<int, int> P;

const int INF = 1145141919;
const int DEPTH = 17;
struct SegTree {
	P d[1 << (DEPTH + 1)];	//(val, pos)
	SegTree() {
		int i;
		rep(i, 1 << (DEPTH + 1)) d[i] = P(0, 0);
	}
	void update(int pos, int x) {
		pos += (1 << DEPTH) - 1;
		d[pos] = P(x, pos - (1 << DEPTH) + 1);
		while (pos > 0) {
			pos = (pos - 1) / 2;
			d[pos] = min(d[pos * 2 + 1], d[pos * 2 + 2]);
		}
	}
	P query(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return P(INF, -1);
		if (l <= a && b <= r) return d[id];
		P u = query(l, r, a, (a + b) / 2, id * 2 + 1);
		P v = query(l, r, (a + b) / 2, b, id * 2 + 2);
		return min(u, v);
	}
};

int n, q;
int a[100000];
int type, l, r;
SegTree seg;

signed main() {
	int i;
	
	cin >> n >> q;
	rep(i, n) cin >> a[i];
	rep(i, n) seg.update(i, a[i]);
	rep(i, q) {
		cin >> type >> l >> r;
		l--; r--;
		if (type == 1) {
			seg.update(l, a[r]);
			seg.update(r, a[l]);
			swap(a[l], a[r]);
		}
		else {
			P res = seg.query(l, r + 1);
			cout << res.second + 1 << endl;
		}
	}
	return 0;
}
0