結果

問題 No.875 Range Mindex Query
ユーザー utsumi_pgutsumi_pg
提出日時 2019-09-07 09:50:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 41,212 KB
実行使用メモリ 5,104 KB
最終ジャッジ日時 2023-09-08 11:47:22
合計ジャッジ時間 2,523 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 123 ms
5,076 KB
testcase_12 AC 99 ms
4,380 KB
testcase_13 AC 87 ms
5,104 KB
testcase_14 AC 86 ms
5,076 KB
testcase_15 AC 115 ms
5,004 KB
testcase_16 AC 91 ms
5,060 KB
testcase_17 AC 98 ms
4,952 KB
testcase_18 AC 95 ms
5,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
static const int MAX_N = 100000;
static const int INF = 1 << 30;

int N, Q;
int A[MAX_N];

int n_;
P dat[4 * MAX_N];

void init(){
	n_ = 1;
	while(n_ < N) n_ *= 2;
	for(int i = 0; i < 2 * n_ - 1; i++){
		dat[i] = P(INF, -1);
	}
}
void update(int i, int x){
	dat[i + n_ - 1] = P(x, i);
	int k = i + n_ - 1;
	while(k > 0){
		k = (k - 1) / 2;
		if(dat[2 * k + 1].first < dat[2 * k + 2].first) dat[k] = dat[2 * k + 1];
		else dat[k] = dat[2 * k + 2];
	}
}
P find(int a, int b, int k, int l, int r){
	if(r <= a || b <= l) return P(INF, -1);
	if(a <= l && r <= b) return P(dat[k].first, dat[k].second);
	P vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
	P vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
	if(vl.first < vr.first) return P(vl.first, vl.second);
	else return P(vr.first, vr.second);
}

int main(){
	scanf("%d %d", &N, &Q);
	init();
	for(int i = 0; i < N; i++){
		int a;
		scanf("%d", &a);
		update(i, a);
	}
	for(int i = 0; i < Q; i++){
		int op;
		scanf("%d", &op);
		if(op == 1){
			int l, r;
			scanf("%d %d", &l, &r);
			l--; r--;
			int bf = find(l, l + 1, 0, 0, n_).first;
			update(l, find(r, r + 1, 0, 0, n_).first);
			update(l, find(r, r + 1, 0, 0, n_).first);
			update(r, bf);
			update(r, bf);
		}else{
			int l, r;
			scanf("%d %d", &l, &r);
			l--; r--;
			printf("%d\n", find(l, r + 1, 0 , 0 , n_).second + 1);
		}
	}
	return 0;
}
0