fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ll n,t;
  5. int main()
  6. {
  7. if (fopen("sapxep.inp","r"))
  8. {
  9. freopen("sapxep.inp","r",stdin);
  10. freopen("sapxep.out","w",stdout);
  11. }
  12. cin >> n;
  13. vector<ll> a(n), b(n);
  14. for (ll i = 0; i < n; i++)
  15. {
  16. cin >> a[i];
  17. b[i] = a[i];
  18. }
  19. sort(b.begin(), b.end());
  20. vector<ll> l, r;
  21. for (ll i = 0; i < n; i++)
  22. {
  23. if (a[i]==b[i]) continue;
  24. t=-1;
  25. for (ll j=i+1; j<n; j++)
  26. {
  27. if (a[j] == b[i])
  28. {
  29. t = j;
  30. break;
  31. }
  32. }
  33. if (t != -1)
  34. {
  35. reverse(a.begin() + i, a.begin() + t + 1);
  36. l.push_back(i + 1);
  37. r.push_back(t + 1);
  38. }
  39. }
  40.  
  41. cout<<l.size()<<endl;
  42. for (ll i = 0; i<l.size(); i++)
  43. cout << l[i] << ' ' << r[i] << endl;
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
0