結果

問題 No.875 Range Mindex Query
ユーザー Mr.SpockMr.Spock
提出日時 2021-02-10 00:58:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 1,832 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 92,836 KB
実行使用メモリ 7,952 KB
最終ジャッジ日時 2023-09-21 12:23:05
合計ジャッジ時間 3,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 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 144 ms
7,768 KB
testcase_12 AC 122 ms
4,616 KB
testcase_13 AC 99 ms
7,760 KB
testcase_14 AC 96 ms
7,900 KB
testcase_15 AC 136 ms
7,880 KB
testcase_16 AC 191 ms
7,928 KB
testcase_17 AC 205 ms
7,848 KB
testcase_18 AC 200 ms
7,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
const ll siz = 2e5 + 7;
pair<int, int> t[4 * siz];
int n, q;
pair<int, int> combine(pair<int, int>a, pair<int, int>b) {
	if (a.first > b.first)return b;
	return a;
}
void build(int a[], int v, int tl, int tr) {
	if (tl == tr) {
		t[v] = {a[tl], tl};
	} else {
		int tm = (tl + tr) / 2;
		build(a, v * 2, tl, tm);
		build(a, v * 2 + 1, tm + 1, tr);
		t[v] = combine(t[v * 2], t[v * 2 + 1]);
	}
}
pair<int, int> query(int v, int tl, int tr , int l , int r) {
	if (l > r)return {1e9, 1e9};
	if (l == tl && r == tr) {
		return t[v];
	}
	int tm = (tr + tl) / 2;
	return combine(query(2 * v, tl, tm, l, min(r, tm)) , query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(int v, int tl, int tr, int pos, int new_val) {
	if (tl == tr) {
		t[v] = {new_val, pos};
	} else {
		int tm = (tl + tr) / 2;
		if (pos <= tm)
			update(v * 2, tl, tm, pos, new_val);
		else
			update(v * 2 + 1, tm + 1, tr, pos, new_val);
		t[v] = combine(t[v * 2] , t[v * 2 + 1]);
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> q;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	pair<int, int>y = combine({1, 0}, {0, 3});
	build(a, 1, 0, n - 1 );
	for (int i = 0; i < q; i++) {
		int type;
		cin >> type;
		int l, r;
		cin >> l >> r;
		--l, --r;
		if (type == 1) {
			int Prev_l = a[l];
			int Prev_r = a[r];
			swap(a[l], a[r]);
			update(1, 0, n - 1, l, Prev_r);
			update(1, 0, n - 1, r, Prev_l);
		} else {
			pair<int, int>x = query(1, 0, n - 1 , l , r);
			cout << x.second + 1 << endl;
		}
	}
}
0