fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<ll, ll> Pair;
  5. #define pb push_back
  6.  
  7. int main() {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10.  
  11. ll n;
  12. cin >> n;
  13. vector<ll> a(n + 1), b(n + 1);
  14.  
  15. for (ll i = 1; i <= n; i++) cin >> a[i];
  16. for (ll i = 1; i <= n; i++) cin >> b[i];
  17.  
  18. vector<Pair> ans;
  19. vector<char> ch;
  20. ans.pb({1, n});
  21. ch.pb('I');
  22. sort(a.begin() + 1, a.end());
  23. for (ll i = 1; i <= n; i++) {
  24. if (a[i] == b[i]) continue;
  25. ll j = i + 1;
  26. while (a[j] != b[i]) j++;
  27. sort(a.begin() + i, a.begin() + j + 1);
  28. ans.pb({i, j});
  29.  
  30. if (b[i] > a[i]) {
  31. ch.pb('D');
  32. reverse(a.begin() + i, a.begin() + j + 1);
  33. }
  34. else ch.pb('I');
  35. }
  36.  
  37. cout << ans.size() << "\n";
  38. for (ll i = 0; i < ans.size(); i++) {
  39. cout << ans[i].first << " " << ans[i].second << " " << ch[i] << "\n";
  40. }
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 5296KB
stdin
5
2 4 5 1 3
5 4 3 2 1
stdout
2
1 5 I
1 5 D