Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define vi vector<ll>
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umii unordered_map<ll,ll,custom_hash>
#define mii map<ll,ll>
#define FOR(vec) for(auto &x : vec) cin >> x;
#define FOR1(vec) for(int i = 1 ; i<= vec.size()-1; i++) cin >> vec[i];

const int M = 998244353;
const int N = 2e5+10;
const int maxint = 2e9 + 1;

// Binary Exponentiation
// int binExp(int a, int b){
// 	int ans = 1;
// 	while(b){
// 		if(b&1){
// 			ans = (ans*1LL*a)%M;
// 		}
// 		a = (a*1LL*a)%M;
// 		b>>=1;
// 	}
// 	return ans;
// }

// DSU CODE

// int parent[N];
// int size[N];
// void make(int v, int parent[], int size[]){
//     parent[v] = v;
//     size[v] = 1;
// }

// int find(int v, int parent[]){
//     if(v == parent[v]) return v;
//     return parent[v] = find(parent[v], parent);
// } // O(alpha(n)) time complexity, grows very slowly

// void Union(int a, int b, int parent[], int size[]){
//     a = find(a, parent);
//     b = find(b, parent);
//     if(a != b){
//         if(size[a] < size[b]) swap(a, b);
//         parent[b] = a;
//         size[a] += size[b];
//     }
// }

int r=0, l=0;
int dp[32][2];

ll func(int bit,int prevNum){
    if(bit == -1){
        if(prevNum != l && prevNum != r) return prevNum;
        else return 0;
    } 

    int l_bit = (l>>bit);
    int r_bit = (r>>bit);

    ll ans1 = 0, ans2 = 0;
    if( ((prevNum<<1)+1) <= r_bit  ){
        if(dp[bit][1] != -1) ans1 = dp[bit][1];
        else ans1 = func(bit - 1, (prevNum<<1)+1);
        dp[bit][1] = ans1;
        // if(ans1 == r || ans1 == l) ans1 = 0; 
    }
    if( ((prevNum<<1)) >= l_bit  ){
        if(dp[bit][0] != -1) ans2 = dp[bit][0];
        else ans2 = func(bit - 1, (prevNum<<1));
        dp[bit][0] = ans2;
        // if(ans2 == r || ans2 == l) ans2 = 0; 
    }

    ll ans = 0;
    if(ans1 && ans2){
        if(((ans1^l)+(ans1^r)) > ((ans2^l)+(ans2^r)) ){
            ans = ans1;
        }else ans = ans2;
    }else ans = max(ans1, ans2);

    return ans;
    // cout<<bit<<" "<<prevNum<<" "<<(prevNum<<1)<<" currbits: "<<l_bit<<" "<<r_bit<<endl;
    // return max(ans1, ans2);
}

void solve(){
    memset(dp, -1, sizeof(dp));
    cin>>l>>r;
    int max_bits = log2(r);
    cout<<l<<" "<<func(max_bits , 0)<<" "<<r<<endl;
}	



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin>>t;
	while(t--){
		solve();
	}	
}





Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define vi vector<ll>
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umii unordered_map<ll,ll,custom_hash>
#define mii map<ll,ll>
#define FOR(vec) for(auto &x : vec) cin >> x;
#define FOR1(vec) for(int i = 1 ; i<= vec.size()-1; i++) cin >> vec[i];

const int M = 998244353;
const int N = 2e5+10;
const int maxint = 2e9 + 1;

// Binary Exponentiation
// int binExp(int a, int b){
// 	int ans = 1;
// 	while(b){
// 		if(b&1){
// 			ans = (ans*1LL*a)%M;
// 		}
// 		a = (a*1LL*a)%M;
// 		b>>=1;
// 	}
// 	return ans;
// }

// DSU CODE

// int parent[N];
// int size[N];
// void make(int v, int parent[], int size[]){
//     parent[v] = v;
//     size[v] = 1;
// }

// int find(int v, int parent[]){
//     if(v == parent[v]) return v;
//     return parent[v] = find(parent[v], parent);
// } // O(alpha(n)) time complexity, grows very slowly

// void Union(int a, int b, int parent[], int size[]){
//     a = find(a, parent);
//     b = find(b, parent);
//     if(a != b){
//         if(size[a] < size[b]) swap(a, b);
//         parent[b] = a;
//         size[a] += size[b];
//     }
// }

// int r=0, l=0;
// int dp[32];

// ll func(int bit,int prevNum){
//     if(bit == -1){
//         if(prevNum != l && prevNum != r) return prevNum;
//         else return 0;
//     } 

//     if(dp[bit] != -1) return dp[bit];
//     int l_bit = (l>>bit);
//     int r_bit = (r>>bit);

//     ll ans1 = 0, ans2 = 0;
//     if( ((prevNum<<1)+1) <= r_bit  ){
//         // if(dp[bit][1] != -1) ans1 = dp[bit][1];
//         ans1 = func(bit - 1, (prevNum<<1)+1);
//         // dp[bit][1] = ans1;
//         // if(ans1 == r || ans1 == l) ans1 = 0; 
//     }
//     if( ((prevNum<<1)) >= l_bit  ){
//         // if(dp[bit][0] != -1) ans2 = dp[bit][0];
//         ans2 = func(bit - 1, (prevNum<<1));
//         // dp[bit][0] = ans2;
//         // if(ans2 == r || ans2 == l) ans2 = 0; 
//     }

//     ll ans = 0;
//     if(ans1 && ans2){
//         if(((ans1^l)+(ans1^r)) > ((ans2^l)+(ans2^r)) ){
//             ans = ans1;
//         }else ans = ans2;
//         dp[bit] = ans;
//     }else ans = max(ans1, ans2);


//     cout<<bit<<" "<<prevNum<<" "<<dp[bit]<<endl;
//     return ans;
    
//     // return max(ans1, ans2);
// }

void solve(){
    // memset(dp, -1, sizeof(dp));
    int l,r;
    cin>>l>>r;
    // int max_bits = log2(r);
    // cout<<l<<" "<<func(max_bits , 0)<<" "<<r<<endl;
    int b = 0;

    int startBit = 0;
    for (int i = 30; i >= 0; --i) {
        if((l>>i) != (r>>i)){
            startBit = i;
            break;
        }else{
            b = b | (((l>>i)&1)<<i) ;
        }
    }

    int num_zeroes = 0;
    int num_ones = 0;

    for (int i = 0; i <= startBit; ++i){
        if(((l>>i)&1) && ((r>>i)&1)){
            // nothing
            num_zeroes=1;
            num_ones = 0;
        }else if(!((l>>i)&1) && !((r>>i)&1)){
            num_ones = 1;
            num_zeroes = 0;
            b = b | (1<<i);
        }else{
            if(num_zeroes == 1){
                b = b | (1<<i);
            }else if(num_ones == 1){
                // nothing
            }else{
                ll l1 = ((1<<(i+1))-1)&(l);
                ll l2 = ((1<<(i+1))-1)&(r);
                ll b1 = ((1<<(i+1))-1)&(b);
                if( b1 == l1 ){
                    b = b | (1<<i);
                }else if(b1 == l2){
                    // nothing
                }
            }
        }
    }
    // cout<<startBit<<endl;
    cout<<l<<" "<<b<<" "<<r<<endl;

}	



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin>>t;
	while(t--){
		solve();
	}	
}