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. int main()
  43. {
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(NULL);
  46. // freopen("xortransform.in","r",stdin);
  47. // freopen("xortransform.out","w",stdout);
  48. // #ifndef ONLINE_JUDGE
  49. // freopen("input.txt","r",stdin);
  50. // freopen("output.txt","w",stdout);
  51. // #endif
  52. int z=1;
  53. cin>>z;
  54. f(i,1,z+1)
  55. {
  56. //cout<<"Case #"<<i<<": ";
  57. ll n;
  58. cin>>n;
  59. vector<ll> a(n+1),pos(n+1);
  60. f(i,1,n+1)
  61. cin>>a[i],pos[a[i]]=i;
  62. vector<pair<ll,ll> > ans;
  63. bool flag=1;
  64. while(flag)
  65. {
  66. flag=0;
  67. f(i,1,n)
  68. {
  69. if(pos[i]>pos[i+1])
  70. ans.pb({pos[i+1],pos[i]}),swap(pos[i],pos[i+1]),flag=1;
  71. }
  72. }
  73. cout<<sz(ans)<<"\n";
  74. f(i,0,sz(ans))
  75. cout<<ans[i].ff<<" "<<ans[i].ss<<"\n";
  76. }
  77. }
Success #stdin #stdout 0.01s 5432KB
stdin
3
3
3 2 1
2
1 2
4
4 1 2 3
stdout
3
2 3
1 3
1 2
0
3
1 4
1 3
1 2