Advertisement
dimuster

Untitled

Sep 28th, 2021
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4.  
  5. using namespace std;
  6.  
  7. vector<int> doIt(vector<int> &a, int l, int r) {
  8.     int temp = a[r];
  9.     for (int i = r; i > l; i--) {
  10.         a[i] = a[i - 1];
  11.     }
  12.     a[l] = temp;
  13.     return a;
  14. }
  15.  
  16. int main() {
  17.     ios_base::sync_with_stdio(false);
  18.     cin.tie(NULL);
  19.    
  20.     int n;
  21.     cin >> n;
  22.     while (n--) {
  23.         int s, l, r;
  24.         int counter = 0;
  25.         cin >> s;
  26.         vector<int> a(s + 1);
  27.         vector<pair<int, int>> b;
  28.         for (int i = 1; i <= s; i++) cin >> a[i];
  29.         for (int i = 1; i <= s; i++) {
  30.             l = i;
  31.             bool ok = false;
  32.             int min = l;
  33.             for (int j = i; j <= s; j++) {
  34.                 if (a[j] < a[min]) {
  35.                     min = j;
  36.                     ok = true;
  37.                 }
  38.             }
  39.             if (!ok) continue;
  40.             counter++;
  41.             r = min;
  42.             pair<int, int> x;
  43.             x.first = l;
  44.             x.second = r;
  45.             b.push_back(x);
  46.             a = doIt(a, l, r);
  47.         }
  48.         cout << counter << "\n";
  49.         for (int i = 0; i < b.size(); i++) {
  50.             cout << b[i].first << " " << b[i].second << " " << b[i].second - b[i].first << "\n";
  51.         }
  52.     }
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement