結果

問題 No.875 Range Mindex Query
ユーザー ransewhaleransewhale
提出日時 2019-09-06 21:43:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,281 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 164,376 KB
実行使用メモリ 4,960 KB
最終ジャッジ日時 2023-09-06 23:20:32
合計ジャッジ時間 5,075 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

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;
	}
	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 INF;
	}
	if(r-l>1){
		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;
		}
	}else{
		return segtree[i];
	}
}

int main(void){
	int q,i,t,l,r,m;
	scanf("%d%d",&n,&q);
	fill(a,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