結果

問題 No.875 Range Mindex Query
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-01-20 20:20:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,484 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 87,676 KB
実行使用メモリ 39,220 KB
最終ジャッジ日時 2023-09-05 12:41:46
合計ジャッジ時間 7,591 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//範囲内の最小値を求めよという問題と間違えた。
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <vector>
//int maxr=131071;
int maxr=7;
using namespace std;
set<int> st[270000];
map<int,int> ms;
int f3(int no,int l,int r,int l2,int r2){
	
	int res=(*(st[no].begin()));
	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){
	st[no].erase(n1);
	st[no].insert(n2);
	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){
	st[no].insert(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+1;
	}
	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+1;
			ms[as[r]]=l+1;
			swap(as[l],as[r]);
		}else{
			//cout<<f3(0,l,r,0,maxr)<<endl;
			cout<<ms[f3(0,l,r,0,maxr)]<<endl;
		}
		
	}
	
	return 0;
}
0