結果

問題 No.875 Range Mindex Query
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-01-20 22:09:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,515 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 91,512 KB
実行使用メモリ 94,944 KB
最終ジャッジ日時 2023-09-05 14:27:17
合計ジャッジ時間 5,326 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
16,356 KB
testcase_01 AC 12 ms
16,500 KB
testcase_02 AC 14 ms
16,624 KB
testcase_03 AC 8 ms
16,068 KB
testcase_04 AC 10 ms
16,300 KB
testcase_05 AC 11 ms
16,864 KB
testcase_06 AC 13 ms
16,868 KB
testcase_07 AC 12 ms
16,232 KB
testcase_08 AC 11 ms
16,524 KB
testcase_09 AC 10 ms
16,300 KB
testcase_10 AC 15 ms
16,748 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 997 ms
91,980 KB
testcase_17 AC 1,044 ms
94,624 KB
testcase_18 AC 1,027 ms
94,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <vector>
int maxr=131071;
//int maxr=7;
using namespace std;
map<int,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*2;
	}else if(l2==r2){
		return (*(st[no].begin())).first;
	}else if(l<=l2 && r2<=r){
		//cout<<l<<" "<<l2<<" "<<r2<<" "<<r<<" "<<res<<endl;
		return (*(st[no].begin())).first;
		
	}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;
	}
	
}

void f2(int no,int p1,int n1,int n2,int l,int r){
	if(no!=0){
		st[no][n1]--;
		st[no][n2]++;
		if(st[no][n1]==0)st[no].erase(n1);
	}
	if(l==r){
		return ;
	}else{
		int m=(l+r)/2;
		if(p1<=m){
			f2(no*2+1,p1,n1,n2,l,m);
		}else{
			f2(no*2+2,p1,n1,n2,m+1,r);
		}
	}
}
void f(int no,int p1,int n1,int l,int r){
	if(no==0){
		st[no][1]=1;
	}else{
		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;
	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,l,as[l],as[r],0,maxr);
			f2(0,r,as[r],as[l],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