結果

問題 No.875 Range Mindex Query
ユーザー QCFiumQCFium
提出日時 2019-09-06 21:36:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,394 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 171,288 KB
実行使用メモリ 5,692 KB
最終ジャッジ日時 2023-09-06 22:58:33
合計ジャッジ時間 3,438 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 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 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 70 ms
5,692 KB
testcase_12 AC 56 ms
4,380 KB
testcase_13 AC 51 ms
5,412 KB
testcase_14 AC 50 ms
5,692 KB
testcase_15 AC 69 ms
5,432 KB
testcase_16 AC 68 ms
5,480 KB
testcase_17 AC 75 ms
5,424 KB
testcase_18 AC 71 ms
5,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct SegTree {
	std::vector<std::pair<int, int> > data;
	int n;
	SegTree(const std::vector<int> &a) {
		for (n = 1; n < (int) a.size(); n *= 2);
		data.resize(2 * n, {1000000000, -1});
		for (int i = 0; i < (int) a.size(); i++) data[i + n] = {a[i], i};
		for (int i = n - 1; i; i--) data[i] = data[i << 1].first < data[i << 1 | 1].first ? data[i << 1] : data[i << 1 | 1];
	}
	void set(int i, int val) {
		for (data[i += n].first = val; i >>= 1; ) data[i] = data[i << 1].first < data[i << 1 | 1].first ? data[i << 1] : data[i << 1 | 1];
	}
	int get(int l, int r) {
		int res = -1;
		int min = 1000000000;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) if (min > data[--r].first) min = data[r].first, res = data[r].second;
			if (l & 1) {
				if (min > data[l].first) min = data[l].first, res = data[l].second;
				l++;
			}
		}
		return res;
	}
	std::pair<int, int> operator [] (size_t i) { return data[i + n]; }
};

int main() {
	int n = ri();
	int q = ri();
	std::vector<int> a(n);
	for (int i = 0; i < n; i++) a[i] = ri();
	SegTree tree(a);
	for (int i = 0; i < q; i++) {
		int t = ri();
		int l = ri() - 1, r = ri() - 1;
		if (t == 1) {
			int x = tree[l].first, y = tree[r].first;
			tree.set(l, y);
			tree.set(r, x);
		} else {
			printf("%d\n", tree.get(l, r + 1) + 1);
		}
	}
	return 0;
}

0