結果

問題 No.875 Range Mindex Query
ユーザー satashunsatashun
提出日時 2019-09-06 21:24:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,721 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 172,312 KB
実行使用メモリ 5,464 KB
最終ジャッジ日時 2023-09-06 22:06:07
合計ジャッジ時間 4,584 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,456 KB
testcase_01 AC 4 ms
5,216 KB
testcase_02 AC 5 ms
5,224 KB
testcase_03 AC 3 ms
5,132 KB
testcase_04 AC 3 ms
5,092 KB
testcase_05 AC 3 ms
5,272 KB
testcase_06 AC 4 ms
5,284 KB
testcase_07 AC 4 ms
5,272 KB
testcase_08 AC 3 ms
5,264 KB
testcase_09 AC 4 ms
5,308 KB
testcase_10 AC 4 ms
5,100 KB
testcase_11 AC 203 ms
5,412 KB
testcase_12 AC 169 ms
5,344 KB
testcase_13 AC 143 ms
5,408 KB
testcase_14 AC 140 ms
5,364 KB
testcase_15 AC 191 ms
5,416 KB
testcase_16 AC 258 ms
5,464 KB
testcase_17 AC 290 ms
5,408 KB
testcase_18 AC 282 ms
5,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int SZ = 1 << 17;

struct segtree {
	vector<pii> dat;

	void init() {
		dat.resize(SZ * 2);
		rep(i, SZ * 2) dat[i] = mp(INT_MAX, -1);
	}

	void update(int pos, int x) {
		pos += SZ - 1;
		dat[pos] = mp(x, pos - (SZ - 1));

		while (pos > 0) {
			pos = (pos - 1) / 2;
			dat[pos] = min(dat[pos * 2 + 1], dat[pos * 2 + 2]);
		}
	}

	pii get(int a, int b, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return mp(INT_MAX, -1);
		if (a <= l && r <= b) return dat[k];
		return min(get(a, b, k * 2 + 1, l, (l + r) / 2), get(a, b, k * 2 + 2, (l + r) / 2, r));
	}
};

int main() {
	int N, Q;
	cin >> N >> Q;
	vi a(N);
	segtree seg;
	seg.init();

	rep(i, N) {
		cin >> a[i];
		seg.update(i, a[i]);
	}

	rep(i, Q) {
		int t, l, r;
		cin >> t >> l >> r;
		--l; --r;

		if (t == 1) {
			int p = a[l], q = a[r];
			seg.update(l, q);
			seg.update(r, p);
			swap(a[l], a[r]);
		} else {
			int ans = seg.get(l, r+1).se;
			printf("%d\n", ans + 1);
		}
	}

	return 0;
}
0