建行网站网址,wordpress用户组设置,php网站开发实例教程,做旅游网站运营给出长为 n 的序列 a,你可以对序列 a 进行以下操作#xff1a; 选择 l,r (1 ≤ l,r ≤ n) #xff0c;交换 a[l],a[r].
请求出在任意多次操作后#xff0c;序列 a 能否满足 a[1]a[n] a[2]a[n-1] a[3]a[n-2] ……a[n/2]a[n1-(n/2)]. 可以证明如果有解#xff0c;操作次数…给出长为 n 的序列 a,你可以对序列 a 进行以下操作 选择 l,r (1 ≤ l,r ≤ n) 交换 a[l],a[r].
请求出在任意多次操作后序列 a 能否满足 a[1]a[n] a[2]a[n-1] a[3]a[n-2] ……a[n/2]a[n1-(n/2)]. 可以证明如果有解操作次数不大于 n.
输入 第一行包含一个整数 T (1 ≤ T ≤ 1e4)表示测试用例的组数。 每组测试用例的第一行包含一个整数 n (1 ≤ n ≤ 2e5)表示序列 a 的长度。 每组测试用例的第二行包含 n 个整数 a1,a2……,an (1 ≤ ai ≤ 1e9)。 对于所有测试用例保证 n 的总和不超过 2e5.
输出 对于每组测试用例如果无解输出 NO。如果有解第一行输出 YES第二行输出一个整数 m (0≤m≤n)之后 m 行每行输出两个整数 l,r。
Input 2 3 1 2 2 5 3 5 1 4 7
Output NO YES 2 3 4 2 5
说明对于第二组测试用例交换后的序列为 3 7 4 1 5。
#include bits/stdc.h
using namespace std;
#define int long long
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef pairint,int PII;
const double PIacos(-1.0);
const int N2e610;
int n;
struct node
{int x,id;
}a[N];
bool cmp(node a,node b)
{return a.xb.x;
}
int now[N],w[N];
vector PII ans;
void solve()
{cinn;for (int i1;in;i) {cina[i].x;a[i].idi;}sort (a1,an1,cmp);int l1,rn;int suma[l].xa[r].x;bool flag1;while (lr) //暴力判断{if (a[l].xa[r].x!sum){flag0;break;}l,r--;}if (!flag) coutNO\n;else {ans.clear();for (int i1;in;i){now[i]i; //记录每个数现在在哪个位置w[i]i; //记录当前下标序列}for (int i1;in;i){int tonow[a[i].id];if (to!i){ans.push_back({i,to});swap(w[i],w[to]);now[w[i]]i;now[w[to]]to;}}coutYES\n;coutans.size()endl;for (auto [x,y]:ans) coutx yendl;}
}
signed main()
{ios;int t;cint;while (t--) solve();return 0;
}