結果

問題 No.875 Range Mindex Query
ユーザー akun0716akun0716
提出日時 2019-09-07 20:15:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,816 bytes
コンパイル時間 674 ms
コンパイル使用メモリ 76,068 KB
実行使用メモリ 7,504 KB
最終ジャッジ日時 2023-09-09 10:20:14
合計ジャッジ時間 3,328 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,424 KB
testcase_01 AC 2 ms
5,712 KB
testcase_02 AC 3 ms
5,380 KB
testcase_03 AC 2 ms
5,452 KB
testcase_04 AC 2 ms
5,436 KB
testcase_05 AC 2 ms
5,460 KB
testcase_06 AC 3 ms
5,448 KB
testcase_07 AC 3 ms
5,400 KB
testcase_08 AC 2 ms
5,496 KB
testcase_09 AC 2 ms
5,428 KB
testcase_10 AC 2 ms
5,476 KB
testcase_11 AC 138 ms
6,828 KB
testcase_12 AC 114 ms
6,328 KB
testcase_13 AC 95 ms
7,256 KB
testcase_14 AC 94 ms
7,204 KB
testcase_15 AC 130 ms
7,504 KB
testcase_16 AC 187 ms
7,440 KB
testcase_17 AC 202 ms
7,436 KB
testcase_18 AC 195 ms
7,464 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;
#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 9223372036854775807
#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;

const int U = 1 << 17;
pii dat[2000000];

void update(int k, int v) {
	dat[k + U] = make_pair(v, k);
	k += U;
	while (k > 1) {
		k >>= 1;
		dat[k] = min(dat[k * 2], dat[k * 2 + 1]);
	}
}

pii query(int l, int r) {
	l += U;
	r += U;
	pii res(INF, INF);
	while (l <= r) {
		if ((l & 1) == 1)res = min(res, dat[l++]);
		if ((r & 1) == 0)res = min(res, dat[r--]);
		l >>= 1;
		r >>= 1;
	}
	return res;
}

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

	int N, Q;
	cin >> N >> Q;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
		update(i, A[i]);
	}
	while (Q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int l, r;
			cin >> l >> r;
			l--;
			r--;
			swap(A[l], A[r]);
			update(l, A[l]);
			update(r, A[r]);
		}
		else {
			int l, r;
			cin >> l >> r;
			l--;
			r--;
			cout << query(l, r).second + 1 << endl;
		}
	}
	
	return 0;
}

0