結果

問題 No.875 Range Mindex Query
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-01-20 21:39:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,569 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 84,404 KB
実行使用メモリ 85,852 KB
最終ジャッジ日時 2023-09-05 13:51:27
合計ジャッジ時間 4,990 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
20,444 KB
testcase_01 AC 12 ms
16,512 KB
testcase_02 AC 14 ms
16,628 KB
testcase_03 AC 9 ms
16,032 KB
testcase_04 AC 11 ms
16,272 KB
testcase_05 AC 11 ms
16,820 KB
testcase_06 AC 13 ms
16,796 KB
testcase_07 AC 11 ms
16,428 KB
testcase_08 AC 12 ms
16,696 KB
testcase_09 AC 10 ms
16,248 KB
testcase_10 AC 16 ms
16,964 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
map<int,int> ms;
int f3(int no,int l,int r,int l2,int r2){
	
	int res=(*(st[no].begin())).first;
	if(r2<l || r<l2){
		return maxr*2;
	}else if(l2==r2){
		return res;
	}else if(l<=l2 && r2<=r){
		//cout<<l<<" "<<l2<<" "<<r2<<" "<<r<<" "<<res<<endl;
		return res;
	}else{
		int m=(r2+l2)/2;
		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