Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- vector < pair < int , int > > v;
- pair < int , int > ans[1<<20];
- int main(){
- int tc;
- scanf("%d",&tc);
- while (tc--) {
- int n;
- v.clear();
- scanf("%d",&n);
- for(int j = 1 ; j <= n ; j++){
- int x;
- scanf("%d",&x);
- v.push_back({x , j});
- ans[j].first = x;
- }
- sort(v.begin() , v.end());
- int h = v.size() / 2;
- for(int j = 0 ; j < n ; j++)
- ans[v[j].second].second = v[ (j + h) % n ].first;
- bool nosol = 0;
- for(int j = 1 ; j <= n ; j++){
- if(ans[j].first == ans[j].second)
- nosol = 1;
- }
- if(nosol) puts("No");
- else{
- puts("Yes");
- for(int j = 1 ; j <= n ; j++){
- printf("%d ",ans[j].second);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment