QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#784#529114#7902. Strange SortingliyelinMax_FWLFailed.2024-08-24 15:04:132024-08-24 15:04:13

詳細信息

Extra Test:

Accepted
time: 0ms
memory: 3704kb

input:

1
5
3 5 4 2 1

output:

1
1 5

result:

ok ok 1 Test Cases. (1 test case)

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#529114#7902. Strange SortingMax_FWLAC ✓3ms3732kbC++14758b2024-08-24 09:34:162024-08-24 09:34:17

answer

#include <bits/stdc++.h>
#define mp make_pair
using namespace std;

typedef pair<int, int> pii;
const int N = 110;
int T, n, a[N], t[N];
vector<pii> ans;

void Solve(){
	ans.clear();
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		t[i] = a[i];
	}
	
	sort(t + 1, t + n + 1);
	for (int i = n; i >= 1; i--)
		if (a[i] ^ t[i]){
			for (int j = 1; j < i; j++)
				if (a[j] > a[i]){
					sort(a + j, a + i + 1);
					ans.push_back(mp(j, i));
					break;
				}
		}
	
	cout << ans.size() << endl;
	for (auto e : ans){
		int l, r;
		tie(l, r) = e;
		cout << l << " " << r << endl; 
	}
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> T;
	
	while (T--)
		Solve();
	
	return 0;
}