結果

問題 No.875 Range Mindex Query
ユーザー 夜
提出日時 2021-03-03 21:19:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 1,446 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 97,668 KB
実行使用メモリ 11,952 KB
最終ジャッジ日時 2024-04-14 13:00:07
合計ジャッジ時間 3,921 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,356 KB
testcase_01 AC 8 ms
9,356 KB
testcase_02 AC 9 ms
9,484 KB
testcase_03 AC 8 ms
9,360 KB
testcase_04 AC 8 ms
9,360 KB
testcase_05 AC 8 ms
9,360 KB
testcase_06 AC 8 ms
9,488 KB
testcase_07 AC 8 ms
9,356 KB
testcase_08 AC 7 ms
9,360 KB
testcase_09 AC 8 ms
9,360 KB
testcase_10 AC 9 ms
9,360 KB
testcase_11 AC 212 ms
9,876 KB
testcase_12 AC 173 ms
9,872 KB
testcase_13 AC 152 ms
10,128 KB
testcase_14 AC 150 ms
10,128 KB
testcase_15 AC 199 ms
11,952 KB
testcase_16 AC 269 ms
9,996 KB
testcase_17 AC 293 ms
10,256 KB
testcase_18 AC 284 ms
10,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long qinf = 1000000007;
int n, n1;
vector<long long> segtree;
void segset() {
	for (int i = 0; i < 500050; i++) {
		segtree.emplace_back(qinf);
	}
	n1 = n;
	int t = 1;
	while (t < n) {
		t *= 2;
	}
	n = t;
}
void add(int i, long long x) {
	int now = n + i - 1;
	segtree[now] = x;
	while (now > 0) {
		now = now / 2;
		segtree[now] = min(segtree[now * 2], segtree[now * 2 + 1]);
	}
}
long long qans1(int l, int r, int i, int nl, int nr) {
	if (nl > r || l > nr) {
		return qinf;
	}
	else if (nl >= l && nr <= r) {
		return segtree[i];
	}
	else {
		long long x = qans1(l, r, i * 2, nl, (nl + nr) / 2);
		long long y = qans1(l, r, i * 2 + 1, (nl + nr) / 2 + 1, nr);
		return min(x, y);
	}
}
long long q_ans(int l, int r) {
	return qans1(l, r, 1, 1, n);
}
long long a[500050], in[500050];
int main() {
	int q;
	cin >> n >> q;
	segset();
	for (int i = 1; i <= n1; i++) {
		cin >> a[i];
		in[a[i]] = i;
		add(i, a[i]);
	}
	for (int i = 0; i < q; i++) {
		int query, l, r;
		cin >> query >> l >> r;
		if (query == 1) {
			add(l, a[r]);
			add(r, a[l]);
			swap(a[l], a[r]);
			swap(in[a[l]], in[a[r]]);
		}
		else {
			cout << in[q_ans(l, r)] << endl;
		}
	}
}
0