Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 39):
#include<bits/stdc++.h>
#include<stdio.h> 
#include<chrono>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds ; 
using ll = long long ;  
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds ; 
ll inf = (4e18L) + 100 ;
ll ninf = (-4e18L) - 100 ;
const ll mod = 1e9 + 7 ; // 998244353; 
const int MAXN = 2e5 + 100 ; 

void solve_test_case() 
{     
    int n ; 
    cin >> n ; 
    
    vector<int> arr(n+1) ; 
    
    for(int i = 1 ; i <= n ; i++) cin >> arr[i] ; 
    vector<pair<int,int>> ans ;
    vector<bool> visited(n,false) ; 
    for(int j = n  ; j > 0 ; j--) 
    {
        int x = arr[j] ; 
        visited[x] = true ; 
        
        for(int i = x-1 ; i > 0 ; i--) 
        {
            if(visited[i] == true) continue ; 
            ans.push_back({x,i}) ;  
        }
        for(int i = 1 ; i <= x-1 ; i++) 
        {
            if(visited[i] == true) continue ; 
            ans.push_back({i,x}) ; 
        }
        
        for(int i = x+1 ; i <= n ; i++) 
        {
            if(visited[i] == true) continue ;
            ans.push_back({i,x}) ; 
        }
    }
    
    cout << (int)ans.size() << endl; 
    
    for(auto v : ans) 
    {
        cout << v.first << " " << v.second << endl ;
    }
}


int32_t main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    // init_code() ;
    ll t = 1 ; 
    // cin >> t;  
    while(t--) solve_test_case() ; 
    return 0 ; 
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
#include<stdio.h> 
#include<chrono>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds ; 
using ll = long long ;  
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds ; 
ll inf = (4e18L) + 100 ;
ll ninf = (-4e18L) - 100 ;
const ll mod = 1e9 + 7 ; // 998244353; 
const int MAXN = 2e5 + 100 ; 

void solve_test_case() 
{     
    int n ; 
    cin >> n ; 
    
    vector<int> arr(n+1) ; 
    
    for(int i = 1 ; i <= n ; i++) cin >> arr[i] ; 
    vector<pair<int,int>> ans ;
    vector<bool> visited(n+1,false) ; 
    for(int j = n  ; j > 0 ; j--) 
    {
        int x = arr[j] ; 
        visited[x] = true ; 
        
        for(int i = x-1 ; i > 0 ; i--) 
        {
            if(visited[i] == true) continue ; 
            ans.push_back({x,i}) ;  
        }
        for(int i = 1 ; i <= x-1 ; i++) 
        {
            if(visited[i] == true) continue ; 
            ans.push_back({i,x}) ; 
        }
        
        for(int i = x+1 ; i <= n ; i++) 
        {
            if(visited[i] == true) continue ;
            ans.push_back({i,x}) ; 
        }
        

    }
    
    cout << (int)ans.size() << endl; 
    
    for(auto v : ans) 
    {
        cout << v.first << " " << v.second << endl ;
    }
}


int32_t main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    // init_code() ;
    ll t = 1 ; 
    // cin >> t;  
    while(t--) solve_test_case() ; 
    return 0 ; 
}