結果

問題 No.875 Range Mindex Query
ユーザー kenken714kenken714
提出日時 2019-09-07 18:32:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 1,611 ms
コンパイル使用メモリ 76,968 KB
実行使用メモリ 5,976 KB
最終ジャッジ日時 2023-09-09 07:26:40
合計ジャッジ時間 3,861 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 190 ms
5,596 KB
testcase_12 AC 154 ms
4,856 KB
testcase_13 AC 130 ms
5,780 KB
testcase_14 AC 129 ms
5,968 KB
testcase_15 AC 177 ms
5,976 KB
testcase_16 AC 255 ms
5,796 KB
testcase_17 AC 277 ms
5,924 KB
testcase_18 AC 268 ms
5,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

//セグ木
ll dat[510000], sz;

void init(ll n) {
	sz = 1;
	while (sz < n)sz *= 2;
	REP(i, sz) {
		dat[i] = INF;
	}
}

void update(ll k, ll a) { //場所(0-indexed), 値
	k += sz - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]); //更新
	}
}

ll query(ll a, ll b, ll k, ll l, ll r) { //[a, b) 呼ぶとき (a, b, 0, 0, sz)
	if (r <= a or b <= l)return INF;
	if (a <= l and r <= b)return dat[k];
	ll v1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
	ll v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
	return min(v1, v2); //戻り値
}

ll n, q, num[110000];
int main() {
	cin >> n >> q;
	init(n);
	REP(i, n) {
		ll a;
		cin >> a;
		a--;
		update(i, a);
		num[a] = i;
	}
	REP(i, q) {
		ll s, l, r;
		cin >> s >> l >> r;
		l--;
		r--;
		if (s == 1) {
			ll a = dat[l + sz - 1], b = dat[r + sz - 1];
			update(l, b);
			update(r, a);
			num[a] = r;
			num[b] = l;
		}
		else {
			ll a = query(l, r + 1, 0, 0, sz);
			cout << num[a] + 1 << endl;
		}
	}
}
	
0