結果

問題 No.875 Range Mindex Query
ユーザー e869120e869120
提出日時 2019-09-06 21:28:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,358 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 71,544 KB
実行使用メモリ 6,048 KB
最終ジャッジ日時 2023-09-06 22:32:55
合計ジャッジ時間 2,498 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 84 ms
5,884 KB
testcase_12 AC 67 ms
4,828 KB
testcase_13 AC 61 ms
5,992 KB
testcase_14 AC 61 ms
5,820 KB
testcase_15 AC 82 ms
5,920 KB
testcase_16 AC 92 ms
5,888 KB
testcase_17 AC 98 ms
5,900 KB
testcase_18 AC 96 ms
6,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

pair<int, int> dat[1 << 18];
int size_ = 1;

void init(int sz) {
	while (size_ <= sz) size_ *= 2;

	for (int i = 0; i < size_; i++) dat[i + size_] = make_pair(1 << 30, i);
	for (int i = size_ - 1; i >= 1; i--) dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
}

void update(int pos, int x) {
	int cx = pos + size_;
	dat[cx] = make_pair(x, pos);

	while (cx >= 2) {
		cx >>= 1;
		dat[cx] = min(dat[cx * 2], dat[cx * 2 + 1]);
	}
}

pair<int, int> query_(int l, int r, int a, int b, int u) {
	if (l <= a && b <= r) return dat[u];
	if (r <= a || b <= l) return make_pair(1 << 30, 0);

	pair<int, int> v1 = query_(l, r, a, (a + b) >> 1, u * 2);
	pair<int, int> v2 = query_(l, r, (a + b) >> 1, b, u * 2 + 1);
	return min(v1, v2);
}

pair<int, int> query(int l, int r) {
	return query_(l, r, 0, size_, 1);
}

int N, Q, A[1 << 17];

int main() {
	scanf("%d%d", &N, &Q);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	init(N + 1);
	for (int i = 0; i < N; i++) update(i, A[i]);

	for (int i = 0; i < Q; i++) {
		int ty, l, r; scanf("%d%d%d", &ty, &l, &r);
		l--; r--;

		if (ty == 1) {
			swap(A[l], A[r]);
			update(l, A[l]);
			update(r, A[r]);
		}
		if (ty == 2) {
			pair<int, int> Z = query(l, r + 1);
			printf("%d\n", Z.second + 1);
		}
	}
	return 0;
}
0