fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while(t--)
  8. {
  9. vector<int> v;
  10. map<int, int> m,mp;
  11. int n,c=0,d;
  12. cin >> n;
  13.  
  14. for(int i=0;i<n;i++)
  15. {
  16. int a;
  17. cin >> a;
  18. m[i] = a;
  19. v.push_back(a);
  20. }
  21. sort(v.begin(),v.end());
  22. for(int i=0;i<n;i++)
  23. {
  24. mp[i] = v[i];
  25. }
  26. for(int i=0;i<n;i++)
  27. {
  28. if(m[i]==mp[i])
  29. {
  30. c++;
  31. d = i;
  32. }
  33. }
  34. if(c>1 || n==1)
  35. {
  36. cout << "NO" << endl;
  37. }
  38. else if(c==1)
  39. {
  40. cout << "YES" << endl;
  41. cout << n-1 << endl;
  42. for(int i=0;i<n;i++)
  43. {
  44. if(i!=d)
  45. {
  46. cout << m[i] << " ";
  47. }
  48.  
  49. }
  50. cout << endl;
  51. }
  52. else
  53. {
  54. cout << c << endl;
  55. cout << "YES" << endl;
  56. cout << n << endl;
  57. for(int i=0;i<n;i++)
  58. {
  59.  
  60. cout << m[i] << " ";
  61.  
  62. }
  63. cout << endl;
  64. }
  65.  
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5316KB
stdin
3
3
2 2 3
5
4 5 5 2 4
1
1
stdout
NO
0
YES
5
4 5 5 2 4 
NO