Problem: 2057C - Trip to the Olympiad
Language: c++17 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define e '\n'
#define pb push_back
#define yes "yes"
#define no "no"
#define F first
#define S second
//#define srt(a) sort(a,a+n)
//#define srt(v) s5ort(v.begin(),v.end())
//#define srt(u) sort(u.begin(),u.end())
#define loop  for(i=1;i<=n;i++)
const int mod=1e9+7;
const int MOD=998244353;
const int lx=1e5+25;
//pair<ll,ll>p[222222];
//map<ll,ll>mp;
//typedef pair<int, int> pi;
//sort(p,p+n,greater<pair<ll,ll>>());-sort vector pair decending order
//priority_queue<pi,vector<pi>,greater<pi>>pq;
//priority_queue<int,vector<int>,greater<int>>pq;-minheap
//priority_queue<pair<int,int>>pq;
//s.erase(position,length)

void solve(){
    ll l, r, c1=0;
    cin>>l>>r;

    vector<ll>v, v1, v2, v3;
    for(int i=0; i<=30; i++){
        v.pb(pow(2,i));
    }

    ll a, b, c, n = v.size();
    a = r;
    map<ll,ll>mp;
    for(int i=n-1; i>=0; i--){
        if(a >= v[i]){
            v1.pb(1);
            a-=v[i];
            mp[v[i]]++;
        }
        else
            v1.pb(0);
    }
    b = l, c1=0;
    for(int i=n-1; i>=0; i--){
        if(b >= v[i]){
            v2.pb(1);
            b-=v[i];
            mp[v[i]]++;
        }
        else
            v2.pb(0);
    }
    a = 0, b = 0;
    reverse(v.begin(), v.end());
    for(int i=0; i<v1.size(); i++){
        if(v1[i] == v2[i]){
            if(v1[i] == 1)
                a+=v[i], b+=v[i];
        }
        else{
            a+=v[i], b+=(v[i]-1);
            break;
        }
    }

//    for(int i=0; i<v1.size(); i++)
//        cout<<v1[i]<<" "<<" "<<v2[i]<<e;;

    if(r>a)
        c = a+1;
    else
        c = b-1;

    cout<<a<<" "<<b<<" "<<c<<e;
}



int main(){
    fast()
    int test;
    cin>>test;
    while(test--){
        solve();
    }
    return 0;
}

//        **Number Theory***

//        sort(a+1,a+n+1);
//        long long gcd=a[1];
//        for(int i=2;i<=n;i++){
//             gcd = __gcd(a[i],gcd);
//        }
//         cout<<gcd<<endl;

//        long long s[10];
//        for(i=1;i<10;i++)
//            s[i]=i;
//        s[1]=2;
//        for(i=2;i<10;i++){
//            q=s[i]*s[i-1];
//            long long gcd = __gcd(s[i],s[i-1]);
//            s[i]=q/gcd;//   -LCM
//        }
//        for(i=1;i<10;i++)
//            cout<<s[i]<<" ";
//        *Linear Diophantine Equations
//        1.ax+by=c
//        there will be a solution if gcd(a,b) can divide c

//        convert string to int and int to string
//        string t;
//        cin>>n;
//        p=stoi(t);
//        std:: string s = std::to_string(n);
//        cout<<s;
//        build all permutation of a string
//        string s="1234";
//        do {
//            std::cout<<s<<std::endl;
//        } while (std::next_permutation(s.begin(),s.end()));


//    Harmonic series-nlogn
//    for(i=1;i<=n;i++){
//        for(j=i;j<=n;j+=i)
//            operation.....
//    }



Code 2:
#include<bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define e '\n'
#define pb push_back
#define yes "yes"
#define no "no"
#define F first
#define S second
//#define srt(a) sort(a,a+n)
//#define srt(v) s5ort(v.begin(),v.end())
//#define srt(u) sort(u.begin(),u.end())
#define loop  for(i=1;i<=n;i++)
const int mod=1e9+7;
const int MOD=998244353;
const int lx=1e5+25;
//pair<ll,ll>p[222222];
//map<ll,ll>mp;
//typedef pair<int, int> pi;
//sort(p,p+n,greater<pair<ll,ll>>());-sort vector pair decending order
//priority_queue<pi,vector<pi>,greater<pi>>pq;
//priority_queue<int,vector<int>,greater<int>>pq;-minheap
//priority_queue<pair<int,int>>pq;
//s.erase(position,length)

void solve(){
    ll l, r, c1=0;
    cin>>l>>r;

    vector<ll>v, v1, v2, v3;
    for(int i=0; i<=30; i++){
        v.pb(pow(2,i));
    }

    //reverse(v.begin(), v.end());
    ll a, b, c, n = v.size();
    a = r;
    map<ll,ll>mp;
    for(int i=n-1; i>=0; i--){
        if(a >= v[i]){
            v1.pb(1);
            a-=v[i];
            mp[v[i]]++;
            c1++;
        }
        else if(c1>0)
            v1.pb(0);
    }
    b = l, c1=0;
    for(int i=n-1; i>=0; i--){
        if(b >= v[i]){
            v2.pb(1);
            b-=v[i];
            mp[v[i]]++;
            c1++;
        }
        else if(c1>0)
            v2.pb(0);
    }


    ll x = l+1, y = r-1;
    c1=0, c=0;
    for(int i=n-1; i>=0; i--){
        if(mp[v[i]] == 0){
            if(v[i]>=x && v[i]<=y){
                x-=v[i], y-=v[i];
                v3.pb(1);
                c+=v[i];
            }
            else
                v3.pb(0);

        }
        else if(mp[v[i]]>0){
            ll sum=0;
            for(int j=i-1; j>=0; j--)
                sum+=v[j];
            if(sum>=x && sum<=y)
                v3.pb(0);
            else{
                if(v[i]<=x && v[i]<=y){
                    x-=v[i], y-=v[i];
                    v3.pb(1);
                    c+=v[i];
                }
                else
                    v3.pb(0);
            }
        }

        //cout<<x<<" "<<y<<e;
    }

//    for(int i=0; i<v3.size(); i++)
//        cout<<v3[i]<<" ";
//    cout<<e;
    cout<<l<<" "<<c<<" "<<r<<e;
}



int main(){
    fast()
    int test;
    cin>>test;
    while(test--){
        solve();
    }
    return 0;
}

//        **Number Theory***

//        sort(a+1,a+n+1);
//        long long gcd=a[1];
//        for(int i=2;i<=n;i++){
//             gcd = __gcd(a[i],gcd);
//        }
//         cout<<gcd<<endl;

//        long long s[10];
//        for(i=1;i<10;i++)
//            s[i]=i;
//        s[1]=2;
//        for(i=2;i<10;i++){
//            q=s[i]*s[i-1];
//            long long gcd = __gcd(s[i],s[i-1]);
//            s[i]=q/gcd;//   -LCM
//        }
//        for(i=1;i<10;i++)
//            cout<<s[i]<<" ";
//        *Linear Diophantine Equations
//        1.ax+by=c
//        there will be a solution if gcd(a,b) can divide c

//        convert string to int and int to string
//        string t;
//        cin>>n;
//        p=stoi(t);
//        std:: string s = std::to_string(n);
//        cout<<s;
//        build all permutation of a string
//        string s="1234";
//        do {
//            std::cout<<s<<std::endl;
//        } while (std::next_permutation(s.begin(),s.end()));


//    Harmonic series-nlogn
//    for(i=1;i<=n;i++){
//        for(j=i;j<=n;j+=i)
//            operation.....
//    }



Answer: 1