結果

問題 No.875 Range Mindex Query
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-01-20 23:05:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 5,440 KB
最終ジャッジ日時 2023-09-05 15:31:21
合計ジャッジ時間 3,755 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,472 KB
testcase_01 AC 3 ms
4,400 KB
testcase_02 AC 4 ms
4,532 KB
testcase_03 AC 3 ms
4,476 KB
testcase_04 AC 3 ms
4,664 KB
testcase_05 AC 2 ms
4,596 KB
testcase_06 AC 3 ms
4,448 KB
testcase_07 AC 3 ms
4,500 KB
testcase_08 AC 3 ms
4,404 KB
testcase_09 AC 3 ms
4,584 KB
testcase_10 AC 4 ms
4,540 KB
testcase_11 AC 206 ms
5,196 KB
testcase_12 AC 167 ms
4,876 KB
testcase_13 AC 148 ms
5,388 KB
testcase_14 AC 145 ms
5,072 KB
testcase_15 AC 195 ms
5,100 KB
testcase_16 AC 260 ms
5,048 KB
testcase_17 AC 282 ms
5,440 KB
testcase_18 AC 275 ms
5,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
int maxr=131071;
//int maxr=7;
using namespace std;
int st[270000];
int ms[100017];
int f3(int no,int l,int r,int l2,int r2){
	if(r2<l || r<l2){
		return maxr*3;
	}else if(l2==r2){
		return st[no];
	}else if(l<=l2 && r2<=r){
		//cout<<l<<" "<<l2<<" "<<r2<<" "<<r<<" "<<res<<endl;
		return st[no];
		
	}else{
		int m=(r2+l2)/2;
		int res=f3(no*2+1,l,r,l2,m);
		res=min(res,f3(no*2+2,l,r,m+1,r2));
		return res;
	}
	
}

int f2(int no,int p1,int n1,int l,int r){
	if(l==r){
		st[no]=n1;
		return n1;
	}else{
		int m=(l+r)/2;
		if(p1<=m){
			int res=f2(no*2+1,p1,n1,l,m);
			st[no]=min(res,st[no*2+2]);
		}else{
			int res=f2(no*2+2,p1,n1,m+1,r);
			st[no]=min(res,st[no*2+1]);
		}
		return st[no];
	}
}
void f(int no,int p1,int n1,int l,int r){
	if(st[no]==-1 || st[no]>n1){
		st[no]=n1;
	}
	if(l==r){
		return ;
	}else{
		int m=(l+r)/2;
		if(p1<=m){
			f(no*2+1,p1,n1,l,m);
		}else{
			f(no*2+2,p1,n1,m+1,r);
		}
	}
	
}
int main() {
	int n,q;
	cin>>n>>q;
	vector<int> as;
	memset(st,-1,sizeof(st));
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		as.push_back(a);
		f(0,i,a,0,maxr);
		ms[a]=i;
	}
	for(int i=0;i<q;i++){
		int e,l,r;
		cin>>e>>l>>r;
		l--;
		r--;
		if(e==1){
			f2(0,r,as[l],0,maxr);
			f2(0,l,as[r],0,maxr);
			ms[as[l]]=r;
			ms[as[r]]=l;
			swap(as[l],as[r]);
		}else{
			//cout<<f3(0,l,r,0,maxr)<<endl;
			cout<<ms[f3(0,l,r,0,maxr)]+1<<endl;
		}
		
	}
	
	return 0;
}
0