fork download
  1. #include<bits/stdc++.h>
  2. // #pragma GCC optimize("Ofast")
  3. // #pragma GCC target("avx,avx2,fma")
  4. // #pragma GCC optimization("unroll-loops")
  5. // #pragma GCC optimize("unroll-loops")
  6. // #pragma GCC optimize("fast-math")
  7. // #pragma GCC optimize("no-stack-protector")
  8. // #define ll __int128
  9. #define ll long long
  10. // #define ll int
  11. #define f(i,a,b) for(ll i=a;i<b;i++)
  12. #define mod 1000000007
  13. // #define mod 998244353
  14. #define mp make_pair
  15. #define uniq(v) (v).erase(unique(all(v)),(v).end())
  16. #define ff first
  17. #define ss second
  18. #define rf(i,a,b) for(ll i=a;i>=b;i--)
  19. #define sc(a) scanf("%lld",&a)
  20. #define pf printf
  21. #define sz(a) (int)(a.size())
  22. #define psf push_front
  23. #define ppf pop_front
  24. #define ppb pop_back
  25. #define pb push_back
  26. #define pq priority_queue
  27. #define all(s) s.begin(),s.end()
  28. #define sp(a) setprecision(a)
  29. #define rz resize
  30. #define ld long double
  31. #define inf (ll)1e18
  32. #define ub upper_bound
  33. #define lb lower_bound
  34. #define bs binary_search
  35. #define eb emplace_back
  36. const double pi = acos(-1);
  37. ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;}
  38. ll binpow(ll a, ll b, ll md){ll res=1;a%=md;if(a==0)return 0;while(b!=0){if(b&1)res*=a,res%=md;a*=a,a%=md;b>>=1;}return res%md;}
  39.  
  40. using namespace std;
  41.  
  42. void rotate(ll l, ll r, vector<ll> &a)
  43. {
  44. ll n=sz(a),temp=a[r],id=r;
  45. while(id>l)
  46. a[id]=a[id-1],id--;
  47. a[l]=temp;
  48. }
  49.  
  50. int main()
  51. {
  52. ios_base::sync_with_stdio(false);
  53. cin.tie(NULL);
  54. // freopen("xortransform.in","r",stdin);
  55. // freopen("xortransform.out","w",stdout);
  56. // #ifndef ONLINE_JUDGE
  57. // freopen("input.txt","r",stdin);
  58. // freopen("output.txt","w",stdout);
  59. // #endif
  60. int z=1;
  61. cin>>z;
  62. f(i,1,z+1)
  63. {
  64. //cout<<"Case #"<<i<<": ";
  65. ll n;
  66. cin>>n;
  67. vector<ll> a(n+1);
  68. f(i,1,n+1)
  69. cin>>a[i];
  70.  
  71. bool flag=1;
  72. f(i,1,n+1)
  73. {
  74. if(a[i]!=i)
  75. {
  76. flag=0;
  77. break;
  78. }
  79. }
  80. if(flag)
  81. {
  82. cout<<"0\n";
  83. continue;
  84. }
  85.  
  86. ll pidx=0,sidx=n+1;
  87. f(i,1,n+1)
  88. {
  89. if(a[i]==i)
  90. pidx=i;
  91. else
  92. break;
  93. }
  94. rf(i,n,1)
  95. {
  96. if(a[i]==i)
  97. sidx=i;
  98. else
  99. break;
  100. }
  101. flag=1;
  102. f(i,pidx+1,sidx)
  103. {
  104. if(a[i]==i)
  105. {
  106. flag=0;
  107. break;
  108. }
  109. }
  110. if(flag)
  111. {
  112. cout<<"1\n"<<pidx+1<<" "<<sidx-1<<"\n";
  113. f(i,1,n+1)
  114. cout<<i<<" ";
  115. cout<<"\n";
  116. continue;
  117. }
  118.  
  119. cout<<"2\n1 "<<n<<"\n";
  120. vector<ll> ta=a;
  121. flag=0;
  122. f(i,1,n+10)
  123. {
  124. rotate(1,n,a);
  125. flag=1;
  126. f(j,1,n+1)
  127. {
  128. if(a[j]==j || a[j]==ta[j])
  129. {
  130. flag=0;
  131. break;
  132. }
  133. }
  134. if(flag)
  135. break;
  136. }
  137. if(flag)
  138. {
  139. f(i,1,n+1)
  140. cout<<a[i]<<" ";
  141. cout<<"\n";
  142. }
  143. else
  144. {
  145. swap(a[1],a[2]),flag=0;
  146. f(i,1,n+10)
  147. {
  148. rotate(1,n,a);
  149. flag=1;
  150. f(j,1,n+1)
  151. {
  152. if(a[j]==j || a[j]==ta[j])
  153. {
  154. flag=0;
  155. break;
  156. }
  157. }
  158. if(flag)
  159. break;
  160. }
  161. f(i,1,n+1)
  162. cout<<a[i]<<" ";
  163. cout<<"\n";
  164. }
  165. cout<<"1 "<<n<<"\n";
  166. f(i,1,n+1)
  167. cout<<i<<" ";
  168. cout<<"\n";
  169. }
  170. }
Runtime error #stdin #stdout #stderr 0.01s 5520KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc