Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 281 ms):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cassert>

#include <string>



using namespace std;



void solve()

{

    // try going in reverse

    // so from p to identity permutation

    

    // choose an element x

    

    // all elements to the right of x that are > x

    

    // can pass x, then x will pass and restore the order

    // all elements to the right of x that are < x

    // can pass x, but x cannot pass them

    

    // get largest element to the right of arr[0] that hasn't passed arr[0] yet

    // swap it until it's the first element, record the swaps

    

    // I have this thing that goes from the given array to the identity array

    // how to translate it

    // start with the identity array

    // find mp[i] instead of i

    

    int n;

    cin >> n;

    vector<int> arr(n);

    for (auto& x : arr)

    {

        cin >> x;

    }

    

    vector<int> p(n);

    

    vector<int> mp(n+1);

    vector<int> rev(n+1);

    for (int i = 0; i < n; i++)

    {

        mp[i+1] = arr[i];

        arr[i] = i + 1;

    }

    



    long long count = 0;

    vector<pair<int,int>> swaps;

    /*for (auto x : arr)

    {

        cout << x << ' ';

    }

    cout << endl;*/

    for (int i = n; i > 0; i--)

    {

        int j = 0;

        for (; arr[j] != mp[i]; j++)

            ;

        for (int k = j-1; k >= 0; k--)

        {

            swaps.push_back(make_pair(arr[k+1], arr[k]));

            //swaps.push_back(make_pair(arr[k+1], arr[k]));

            std::swap(arr[k+1], arr[k]);

        }

        /*cout << "i: " << i << ' ';

        for (auto x : arr)

        {

            cout << x << ' ';

        }

        cout << endl;*/

        assert(arr[0] == mp[i]);

    }

    

   /* for (auto x : arr)

    {

        cout << x << ' ';

    }

    cout << endl;

    

    cout << "mp: ";

    for (auto x : arr)

    {

        cout << mp[x] << ' ';

    }

    cout << endl;*/

    cout << swaps.size() << '\n';

    for (auto& p : swaps)

    {

        cout << p.first << ' ' << p.second << '\n';

    }

    

    

}

int main()

{

    int t;

    //cin >> t;

    t = 1;

    while (t--)

    {

        solve();

    }



    return 0;

}

Solution 2 (runtime: 1390 ms):
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long int
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_multiset; // find_by_order, order_of_key
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

const int mod=1e9+7;
#define ull unsigned long long int
#define Cin(v) for(auto &x:v)cin>>x;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define Reverse(v) reverse(v.rbegin(),v.rend());
#define loop(i,s,e) for(int i=s;i<e;i++)
#define rloop(i,n) for(int i=n-1;i>=0;i--)
#define Cout(ans) for(auto &x:ans)cout<<x<<" ";
;
void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    Cin(v);
    map<int, int> mp;
    for(int i=0; i<n; i++){
        mp[v[i]] = i;
    }
    map<vector<int>, int> mpp;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            int l = mp[i], r = mp[j];
            if(r>l) mpp[{i, j}] =2;
            else mpp[{i, j}] = 1;
        }
    }
    mp.clear();
    vector<int> vv(n+1);
    for(int i=1; i<=n; i++){
        vv[i] = i;
        mp[i] = i;
    }
    vector<pair<int, int>> ans;
    int x = 0;
    while(x<n){
        int i=1;
        while(i<n){
            int j = i+1;
            vector<int> tmp = {vv[i], vv[j]};
            sort(all(tmp));
            // cout<<mpp[{2, 3}]<<" ";
            if(mpp[tmp] == 0){
                i++;
                continue;
            }
            ans.push_back({vv[j], vv[i]});
            swap(vv[i], vv[j]);
            mpp[tmp]--;
            i++;
        }
        // Cout(vv);cout<<" ";
        x++;
    }
    cout<<ans.size()<<"\n";
    for(auto &x:ans) cout<<x.first<<" "<<x.second<<"\n";
}
signed main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}