QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#607#404186#7902. Strange SortingliaoyanxuliaoyanxuSuccess!2024-05-03 15:21:232024-05-03 15:21:23

Details

Extra Test:

Runtime Error

input:

1
1
1

output:


result:


IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404186#7902. Strange SortingliaoyanxuRE 5ms3640kbC++23601b2024-05-03 15:21:072024-05-03 15:23:08

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 110
int t,n,a[N];
vector<pair<int,int> > ans;
signed main(){
	cin>>t;
	while(t--){
		ans.clear();
		cin>>n;
if(n==1&&a[1]==0) assert(0);
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		for(int i=1;i<=n;i++){
			if(a[i]!=i){
				for(int j=n;j>=i+1;j--){
					if(a[i]>a[j]){
						ans.push_back(make_pair(i,j));
						sort(a+i,a+j+1);
						break;
					}
				}
			}
		}
		cout<<ans.size()<<endl;
		for(int i=0;i<ans.size();i++){
			cout<<ans[i].first<<' '<<ans[i].second<<endl;
		}
	}
	return 0;
}