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

Previous submission (verdict: Time limit exceeded on test 3):
    #undef _GLIBCXX_DEBUG
    #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;
    #ifndef ONLINE_JUDGE
    #include "debug.h"
    #else
    #define debug(...)
    #define debugArr(...)
    #endif
    #define ll long long
    #define mod 1000000007
    #define endl "\n"
    #define pandeji "abhigyan"
    #define Sum(a) accumulate(a.begin(),a.end(),0)
    #define Sort(a) sort(a.begin(),a.end())
    #define F(i,L,R) for (int i = L; i < R; i++)
    #define FE(i,L,R) for (int i = L; i <= R; i++)
    #define FF(i,R,L) for (int i = R; i > L; i--)
    #define FFE(i,R,L) for (int i = R; i >= L; i--)
    #define fi first
    #define se second
    #define pb push_back
    #define all(a) a.begin(),a.end()
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
    typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set_pair;
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int t;
        cin >> t;
        while (t--) {
            int l,r;
            cin>>l>>r;
            int a = r,b,c;
            int ans = 0;
            bitset<31>br(r);
            bitset<31>bl(0);
            bitset<31>bt;
            FFE(i,30,0){
                if(br[i]){
                    bt.reset(i);
                    if(bt.to_ulong() < l) bt.set(i);
                }
                else{
                    bt.set(i);
                }
                if(bt.to_ulong() >= r) bt.reset(i);
            }
            b = bt.to_ulong();

            F(i,0,30){
                if(!br[i] && !bt[i]) bl.set(i);
            }
            c = bl.to_ulong();
            if(c < l || c == b || c >= r){
                F(i,l,r){
                    if(i == b) continue;
                    if((a^b)+(b^i)+(a^i) > ans){
                        ans = (a^b)+(b^i)+(a^i);
                        c = i;
                    }
                }
            }   
        
            cout<<a<<" "<<b<<" "<<c<<endl;
        }
        return 0;
    }

Submission (verdict: Wrong answer on test 2):
#undef _GLIBCXX_DEBUG
#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;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...)
#define debugArr(...)
#endif
#define ll long long
#define mod 1000000007
#define endl "\n"
#define pandeji "abhigyan"
#define Sum(a) accumulate(a.begin(),a.end(),0)
#define Sort(a) sort(a.begin(),a.end())
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,R,L) for (int i = R; i > L; i--)
#define FFE(i,R,L) for (int i = R; i >= L; i--)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set_pair;
    
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int l,r;
        cin>>l>>r;
        int a = r,b,c;
        int ans = 0;
        int msb = log2(r);
        bitset<30>bl(l);
        bitset<30>bt;
        bitset<30>br(r);
        FFE(i,msb,0){
            if(br[i]){
                bt.reset(i);
                if(bt.to_ulong() < l) bt.set(i);
            }
            else{
                bt.set(i);
            }
            if(bt.to_ulong() >= r) bt.reset(i);
        }
        b = bt.to_ulong();
        bool st = 0;
        FFE(i,msb,0){
            if(!br[i] && !bt[i]){
                st = 1;
                bl.set(i);
                if(bl.to_ulong() == b) bl.reset(i);
            }
            else{
                if(st) bl.reset(i);
                if(bl.to_ulong() == b){
                    st = 1;
                    bl.set(i);
                }
            }
            if(bl.to_ulong() > r) bl.reset(i);
        }
        c = bl.to_ulong();
    
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
    return 0;
}