結果

問題 No.875 Range Mindex Query
ユーザー ransewhaleransewhale
提出日時 2019-09-06 21:34:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,251 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 166,412 KB
実行使用メモリ 9,124 KB
最終ジャッジ日時 2023-09-06 22:47:48
合計ジャッジ時間 5,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 v, int l=0, int r=n, int i=0){
	if(p<l || r<=p){
		return;
	}
	if(r-l>1){
		update(p,v,l,(l+r)>>1,i*2+1);
		update(p,v,(l+r)>>1,r,i*2+2);
		segtree[i] = min(segtree[i*2+1],segtree[i*2+2]);
	}else{
		segtree[i] = v;
	}
}

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);
		return min(vl,vr);
	}else{
		return segtree[i];
	}
}

int main(void){
	int q,i,t,l,r,m;
	cin >> n >> q;
	for(i=0; i<n; ++i){
		cin >> a[i];
		update(i,a[i]);
	}
	for(i=0; i<q; ++i){
		cin >> t >> l >> r;
		--t; --l;
		if(t){
			while(r-l>1){
				m = (l+r)>>1;
				if(query(l,m)<query(m,r)){
					r = m;
				}else{
					l = m;
				}
			}
			cout << r << endl;
		}else{
			--r;
			update(l,a[r]);
			update(r,a[l]);
			swap(a[l],a[r]);
		}
	}
	return 0;
}
0