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

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

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,unroll-loops")

using namespace std;

#define all(a) a.begin(), a.end()
#define rsort(c) sort(all(c)); reverse(all(c))
#define print(a) for(auto x : a) cout << x << " "; cout << endl
#define printall(a) for(auto x:a){ print(x); } cout<<endl
#define input(a) for(auto &x:a) cin>>x
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>


#define int long long

void solve(int tc){
    int l,r;
    cin>>l>>r;
    int a=0, b =l,c=l;
    for(int i = 31;i>=0;i--){
        if(((r>>i)&1)==1){
            a |= (1<<i);
            if(((l>>i)&1)==0) break;
        }
    }
    for(int i = 30;i>=0;i--){
        if(((a>>i)&1)==0) {
            // cout<<i<<endl;
            int nb = b | (1<<i);
            // cout<<nb<<endl;
            if(nb<=r) b = nb;
        }
    }
    if(b==c){
        for(int i =0;i<=30;i++){
            if(((c>>i)&1)==0) {
                b|= (1<<i);
                break;
            }
        }
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    // cout<<"xor: "<<endl;
    // cout<<(a^b) + (b^c) + (a^c)<<endl;
    // cout<<(134 ^ 132) + (132 ^ 137) + (134 ^ 137)<<endl;
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t=1;
    int tt=1;
    cin>>t;

    while(t--){
        // cout<<"Case #"<<tt<<": ";
        // tt++;
        solve(tt++);
    }
}



















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

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,unroll-loops")

using namespace std;

#define all(a) a.begin(), a.end()
#define rsort(c) sort(all(c)); reverse(all(c))
#define print(a) for(auto x : a) cout << x << " "; cout << endl
#define printall(a) for(auto x:a){ print(x); } cout<<endl
#define input(a) for(auto &x:a) cin>>x
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>


#define int long long

void solve(int tc){
    int l,r;
    cin>>l>>r;
    int a=0, b =l,c=l;
    for(int i = 31;i>=0;i--){
        if(((r>>i)&1)==1){
            a |= (1<<i);
            if(((l>>i)&1)==0) break;
        }
    }
    int bb = (1 + log2(r));
    for(int i = 30;i>=0;i--){
        if(((a>>i)&1)==0) {
            // cout<<i<<endl;
            int nb = b | (1<<i);
            // cout<<nb<<endl;
            if(nb<=r) b = nb;
        }
    }
    if(b==c){
        for(int i =0;i<=30;i++){
            if(((c>>i)&1)==0) {
                int nb = b | (1<<i);
            // cout<<nb<<endl;
                if(nb<=r) b = nb;
                else{
                    b = a + 1;
                }
                break;
            }
        }
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    // cout<<"xor: "<<endl;
    // cout<<(a^b) + (b^c) + (a^c)<<endl;
    // cout<<(134 ^ 132) + (132 ^ 137) + (134 ^ 137)<<endl;
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t=1;
    int tt=1;
    cin>>t;

    while(t--){
        // cout<<"Case #"<<tt<<": ";
        // tt++;
        solve(tt++);
    }
}