結果

問題 No.875 Range Mindex Query
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-01-20 20:22:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,484 bytes
コンパイル時間 1,984 ms
コンパイル使用メモリ 94,976 KB
実行使用メモリ 104,040 KB
最終ジャッジ日時 2023-09-05 12:43:31
合計ジャッジ時間 13,752 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
16,000 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 10 ms
16,348 KB
testcase_05 AC 11 ms
16,920 KB
testcase_06 AC 12 ms
16,996 KB
testcase_07 AC 11 ms
16,200 KB
testcase_08 AC 11 ms
16,492 KB
testcase_09 AC 10 ms
16,296 KB
testcase_10 AC 14 ms
16,804 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 1,118 ms
100,312 KB
testcase_17 AC 1,179 ms
103,552 KB
testcase_18 AC 1,173 ms
104,040 KB
権限があれば一括ダウンロードができます

ソースコード

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