結果

問題 No.875 Range Mindex Query
ユーザー akun0716akun0716
提出日時 2019-09-11 14:56:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 2,061 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 75,724 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2023-09-15 13:48:30
合計ジャッジ時間 2,872 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 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,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 130 ms
6,280 KB
testcase_12 AC 105 ms
4,832 KB
testcase_13 AC 87 ms
6,380 KB
testcase_14 AC 86 ms
6,416 KB
testcase_15 AC 124 ms
6,376 KB
testcase_16 AC 191 ms
6,620 KB
testcase_17 AC 209 ms
6,752 KB
testcase_18 AC 206 ms
6,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 2147483647
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

vector<int> value;
int N;

void update(int i, int x) {
	i += N - 1;
	value[i] = x;
	while (i > 0) {
		i = (i - 1) / 2;
		value[i] = min(value[i * 2 + 1], value[i * 2 + 2]);
	}
}

int query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return LLINF;
	if (a <= l && r <= b)return value[k];
	else {
		int c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
		int c2 = query(a, b, 2 * k + 2, (l + r) / 2,r);
		return min(c1, c2);
	}
}


signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int n, q;
	cin >> n >> q;
	N = 1;
	while (N < n)N *= 2;
	value = vector<int>(2 * N - 1);
	VI A(n);
	VI cnt(n + 1);
	REP(i, value.size())value[i] = LLINF;
	REP(i, n) {
		cin >> A[i];
		update(i, A[i]);
		cnt[A[i]] = i;
	}
	REP(i, q) {
		int c;
		cin >> c;
		c--;
		if (!c) {
			int s,t;
			cin >> s >> t;
			
			swap(cnt[A[s - 1]], cnt[A[t - 1]]);

			update(s-1, A[t - 1]);
			update(t-1, A[s - 1]);

			swap(A[t - 1], A[s - 1]);
		}
		else {
			int s, t;
			cin >> s >> t;
			s--;
			t--;
			cout << cnt[query(s, t + 1, 0, 0, N)] + 1 << endl;
		}
	}
	return 0;
}

0