Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>

// Converts decimal to a 32-bit binary array
vll decimalToBinary(int n)
{
    vll binary(32, 0);
    for (int i = 31; i >= 0; i--)
    {
        binary[i] = n % 2;
        n /= 2;
    }
    return binary;
}

// Converts binary array back to decimal
ll binaryArrayToDecimal(vll binary)
{
    ll decimal = 0;
    for (int i = 0; i < 32; i++)
    {
        decimal = (decimal << 1) | binary[i];
    }
    return decimal;
}

int main()
{

    ll t;
    cin >> t;

    while (t--)
    {
        ll l, r;
        cin >> l >> r;

        vll rr = decimalToBinary(r);
        vll aa(32, 0);
        bool lucky = false;

        for (int i = 0; i < 32; i++)
        {
            if (rr[i] == 0 && !lucky)
            {
                aa[i] = 0;
                continue;
            }
            if (rr[i] == 0)
            {
                aa[i] = 1;
            }
            else
            {
                aa[i] = 0;
            }
            lucky = true;
        }

        ll a = -1;
        if (binaryArrayToDecimal(aa) >= l && binaryArrayToDecimal(aa) < r)
        {
            a = binaryArrayToDecimal(aa);
        }
        else
        {

            ll an = binaryArrayToDecimal(aa);
            if (an < l)
            {
                a = l;
            }
            else
            {
                a = r - 1;
            }
        }

        ll c = -1, mx = -1;
        for (int i = max(l, r - 100000); i < r; i++)
        {
            if (i != a)
            {
                ll p = (r ^ i) + (i ^ a);
                if (p > mx)
                {
                    mx = p;
                    c = i;
                }
            }
        }

        cout << a << " " << c << " " << r << endl;
    }

    return 0;
}


Submission (verdict: Accepted):

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>

// Converts decimal to a 32-bit binary array
vll decimalToBinary(int n)
{
    vll binary(32, 0);
    for (int i = 31; i >= 0; i--)
    {
        binary[i] = n % 2;
        n /= 2;
    }
    return binary;
}

// Converts binary array back to decimal
ll binaryArrayToDecimal(vll binary)
{
    ll decimal = 0;
    for (int i = 0; i < 32; i++)
    {
        decimal = (decimal << 1) | binary[i];
    }
    return decimal;
}

int main()
{

    ll t;
    cin >> t;

    while (t--)
    {
        ll l, r;
        cin >> l >> r;

        vll rr = decimalToBinary(r);
        vll aa(32, 0);
        bool lucky = false;

        for (int i = 0; i < 32; i++)
        {
            if (rr[i] == 0 && !lucky)
            {
                aa[i] = 0;
                continue;
            }
            if (rr[i] == 0)
            {
                aa[i] = 1;
            }
            else
            {
                aa[i] = 0;
            }
            lucky = true;
        }

        ll a = -1;
        if (binaryArrayToDecimal(aa) >= l && binaryArrayToDecimal(aa) < r)
        {
            a = binaryArrayToDecimal(aa);
        }
        else
        {

            ll an = binaryArrayToDecimal(aa);
            if (an < l)
            {
                a = l;
            }
            else
            {
                a = r - 1;
            }
        }

        ll c = -1, mx = -1;
        if(a==l){c=l+1;}else{
            c=l;
        }
        

        cout << a << " " << c << " " << r << endl;
    }

    return 0;
}