Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <functional>

 

using namespace __gnu_pbds;

using namespace std;

 

#define int long long

#define F first

#define S second

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

 

const int MOD = 1e9 + 7;

int powMOD(int x, int n) {

    int res = 1;

    while(n > 0) {

        if(n % 2) {

            res *= x;

            res %= MOD;

        }

        x *= x;

        x %= MOD;

        n >>= 1;

    }

    return res;

}

 

int n;

void solve() {

    cin >> n;

    int a[n];

    vector<pair<int, int>> v;

    int b[n];

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

        cin >> a[i];

        v.push_back({a[i], i + 1});

        b[i] = 1;

    }

    

    // 1 2 3

    

    // 1 2 3

    

    vector<pair<int, int>> res;

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

        int current = a[i];

        for(int j = 1; j < current; j++) {

            if(b[j - 1] == 1) {

                res.push_back({current, j});

            }

        }

        b[current - 1] = 0;

    }

    

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

        for(int j = i + 1; j < n; j++) {

            if(a[i] < a[j]) {

                res.push_back({a[j], a[i]});

                res.push_back({a[i], a[j]});

            }

        }

    }

    

    cout << res.size() << "\n";

    for(int i = 0; i < res.size(); i++) {

        cout << res[i].first << " " << res[i].second << "\n";

    }

}

 

 

signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t = 1;

    // cin >> t;

    while(t--) {

        solve();

    }

    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <functional>

 

using namespace __gnu_pbds;

using namespace std;

 

#define int long long

#define F first

#define S second

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

 

const int MOD = 1e9 + 7;

int powMOD(int x, int n) {

    int res = 1;

    while(n > 0) {

        if(n % 2) {

            res *= x;

            res %= MOD;

        }

        x *= x;

        x %= MOD;

        n >>= 1;

    }

    return res;

}

 

int n;

void solve() {

    cin >> n;

    int a[n];

    bool vis[n];

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

        cin >> a[i];

        a[i]--;

        vis[i] = false;

    }

    

    vector<pair<int, int>> res;

    

    // 0 4 3 1 2

    

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

        int current = a[i];

        for(int j = current - 1; j >= 0; j--) {

            if(vis[j] == false) {

                res.push_back({current, j});

            }

        }

        for(int j = 0; j < current; j++) {

            if(vis[j] == false) {

                res.push_back({j, current});

            }

        }

        set<int> st;

        for(int j = i - 1; j >= 0; j--) {

            if(a[j] > current) {

                st.insert(a[j]);

            }

        }

        

        for(auto x: st) {

            res.push_back({x, current});

        }

        vis[current] = true;

    }

    

    cout << res.size() << "\n";

    for(int i = 0; i < res.size(); i++) {

        cout << res[i].first + 1 << " " << res[i].second + 1 << "\n";

    }

}

 

signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t = 1;

    // cin >> t;

    while(t--) {

        solve();

    }

    return 0;

}