結果

問題 No.875 Range Mindex Query
ユーザー autumn-eelautumn-eel
提出日時 2019-09-06 21:23:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,581 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 170,188 KB
実行使用メモリ 7,836 KB
最終ジャッジ日時 2023-09-06 22:02:29
合計ジャッジ時間 3,903 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,624 KB
testcase_01 AC 4 ms
7,552 KB
testcase_02 AC 5 ms
7,608 KB
testcase_03 AC 4 ms
7,680 KB
testcase_04 AC 4 ms
7,560 KB
testcase_05 AC 4 ms
7,564 KB
testcase_06 AC 4 ms
7,556 KB
testcase_07 AC 4 ms
7,816 KB
testcase_08 AC 5 ms
7,636 KB
testcase_09 AC 4 ms
7,576 KB
testcase_10 AC 5 ms
7,632 KB
testcase_11 AC 111 ms
7,652 KB
testcase_12 AC 92 ms
7,836 KB
testcase_13 AC 81 ms
7,608 KB
testcase_14 AC 80 ms
7,556 KB
testcase_15 AC 109 ms
7,664 KB
testcase_16 AC 104 ms
7,768 KB
testcase_17 AC 111 ms
7,620 KB
testcase_18 AC 107 ms
7,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

#define N (1<<18)
template<class T>
struct RMQ{
	pair<T,int>dat[2*N];
	T inf;
	function<pair<T,int>(pair<T,int>,pair<T,int>)>merge;
	RMQ(T Inf,function<pair<T,int>(pair<T,int>,pair<T,int>)>Merge){
		inf=Inf;merge=Merge;
		rep(i,2*N-1){
			dat[i].first=inf;
			if(i>=N-1)dat[i].second=i-N+1;
		}
	}
	void update(int k,T x){
		k+=N-1;
		dat[k].first=x;
		while(k){
			k=(k-1)/2;
			dat[k]=merge(dat[k*2+1],dat[k*2+2]);
		}
	}
	pair<T,int>query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l||r<=a)return make_pair(inf,-1);
		if(a<=l&&r<=b)return dat[k];
		auto lb=query(a,b,k*2+1,l,(l+r)/2);
		auto rb=query(a,b,k*2+2,(l+r)/2,r);
		return merge(lb,rb);
	}
	T getValue(int a,int b){
		return query(a,b).first;
	}
	int getIndex(int a,int b){
		return query(a,b).second;
	}
};
template<class T>
pair<T,int>RangeMax(pair<T,int>a,pair<T,int>b){
	return a.first>=b.first?a:b;
}
template<class T>
pair<T,int>RangeMin(pair<T,int>a,pair<T,int>b){
	return a.first<=b.first?a:b;
}
RMQ<int>seg(INT_MAX,RangeMin<int>);
int main(){
	int n,q;cin>>n>>q;
	rep(i,n){
		int a;scanf("%d",&a);
		seg.update(i,a);
	}
	rep(i,q){
		int t;scanf("%d",&t);
		if(t==2){
			int l,r;scanf("%d%d",&l,&r);l--;
			printf("%d\n",seg.getIndex(l,r)+1);
		}
		else{
			int l,r;scanf("%d%d",&l,&r);l--;
			int x=seg.getValue(l,l+1),y=seg.getValue(r-1,r);
			seg.update(l,y);seg.update(r-1,x);
		}
	}
}
0