結果

問題 No.875 Range Mindex Query
ユーザー ransewhaleransewhale
提出日時 2019-09-06 21:49:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 165,764 KB
実行使用メモリ 4,948 KB
最終ジャッジ日時 2023-09-06 23:35:45
合計ジャッジ時間 3,388 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 102 ms
4,872 KB
testcase_12 AC 81 ms
4,376 KB
testcase_13 AC 79 ms
4,848 KB
testcase_14 AC 77 ms
4,908 KB
testcase_15 AC 102 ms
4,856 KB
testcase_16 AC 96 ms
4,932 KB
testcase_17 AC 103 ms
4,932 KB
testcase_18 AC 100 ms
4,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n,segtree[410410],a[100100];

void update(int p, int l=0, int r=n, int i=0){
	int vl,vr;
	if(p<l || r<=p){
		return;
	}else if(r-l>1){
		update(p,l,(l+r)>>1,i*2+1);
		update(p,(l+r)>>1,r,i*2+2);
		vl = segtree[i*2+1];
		vr = segtree[i*2+2];
		if(a[vl] < a[vr]){
			segtree[i] = vl;
		}else{
			segtree[i] = vr;
		}
	}else{
		segtree[i] = p;
	}
}

int query(int p, int q, int l=0, int r=n, int i=0){
	int vl,vr;
	if(q<=l || r<=p){
		return n;
	}else if(p<=l && r<=q){
		return segtree[i];
	}else{
		vl = query(p,q,l,(l+r)>>1,i*2+1);
		vr = query(p,q,(l+r)>>1,r,i*2+2);
		if(a[vl] < a[vr]){
			return vl;
		}else{
			return vr;
		}
	}
}

int main(void){
	int q,i,t,l,r;
	scanf("%d%d",&n,&q);
	fill(a,a+n,INF);
	a[n] = INF;
	for(i=0; i<n; ++i){
		scanf("%d",&a[i]);
		update(i);
	}
	for(i=0; i<q; ++i){
		scanf("%d%d%d",&t,&l,&r);
		--t; --l;
		if(t){
			printf("%d\n",query(l,r)+1);
		}else{
			--r;
			swap(a[l],a[r]);
			update(l);
			update(r);
		}
	}
	return 0;
}
0