对于这种构造问题
1. 如果想要构造出单调不递减我们可以假设把它都构造同成同一个值
2. 接下来该如何思考呢?我们会发现这两种操作从奇偶性并没有发现任何性质,但根据l,r两个索引顺序我们可以从两边观察a[1]与a[n]是否相等,将两个数变成相等
3. 对于其他数进行一次遍历,分类讨论如果为偶数则选择i与n,奇数则选择1与i
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 10;
int t, n, m, k;
int a[N];
map<string, int> mp1;
vector<string> p;
signed main()
{
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
if (n == 1)
cout << 0 << endl;
else
{
if (a[1] == a[n])
{
int res = a[1];
cout << n - 2 << endl;
for (int i = 2; i <= n - 1; i++)
{
int demo = a[i] + res;
if (demo % 2 == 0)
cout << i << ' ' << n << endl;
else
cout << 1 << ' ' << i << endl;
}
}
else
{
int res = a[1];
int res1 = a[n];
int demo = 0;
if ((res + res1) % 2 == 0)
demo = res1;
else
demo = res;
cout << n - 1 << endl;
cout << 1 << ' ' << n << endl;
for (int i = 2; i <= n - 1; i++)
{
int demo1 = a[i] + demo;
if (demo1 % 2 == 0)
cout << i << ' ' << n << endl;
else
cout << 1 << ' ' << i << endl;
}
}
}
}
return 0;
}