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

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <iomanip>
#include <string>

using namespace std;


using ll = long long;

class BIT {
private:
    vector<int> tree;

public:
    BIT(int size) : tree(size + 1, 0) {}

    // Update the BIT at index i by adding val
    void update(int i, int val) {
        for (++i; i < tree.size(); i += i & -i) {
            tree[i] += val;
        }
    }

    // Query the sum of elements in the BIT up to index i
    int query(int i) {
        int sum = 0;
        for (++i; i > 0; i -= i & -i) {
            sum += tree[i];
        }
        return sum;
    }
};

template<typename T>
void Print(const vector<T> &lst) {
    for (const T &element: lst) {
        cout << element;
    }
    cout << endl;
}

bool Intersects(int l, int r, int left, int right) {
    return (max(l, left) <= min(r, right));
}

long long ModularExponentiation(long long base, long long exponent, long long mod) {
    long long result = 1;
    base = base % mod;

    while (exponent > 0) {
        if (exponent % 2 == 1) {
            result = (result * base) % mod;
        }

        exponent = exponent >> 1; // equivalent to exponent /= 2
        base = (base * base) % mod;
    }
    return result;
}

ll Gcd(ll a, ll b) {
    while (b != 0) {
        long long temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

pair<double, double> GetIntersection(double l, double r, double li, double ri) {
    int intersectionLeft = max(l, li);

    int intersectionRight = min(r, ri);

    if (intersectionLeft <= intersectionRight) {
        return make_pair(intersectionLeft, intersectionRight);
    } else {
        return make_pair(-1, -1);
    }
}

ll Factorial(ll n) {
    if (n == 1 || n == 0) return 1;
    return n * Factorial(n - 1);
}

ll Lcm(ll a, ll b) {
    return a / Gcd(a, b) * b;
}

vector<int> SieveOfEratosthenes(int n) {
    vector<bool> prime(n + 1, true);

    for (int p = 2; p * p <= n; p++) {
        if (prime[p]) {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }

    vector<int> primes;
    for (int p = 2; p <= n; p++)
        if (prime[p])
            primes.push_back(p);

    return primes;
}

vector<int> PrimeDivisors(int n, vector<int> &primes) {
    vector<int> divisors;
    for (int prime: primes) {
        if (prime * prime > n) {
            break;
        }
        while (n % prime == 0) {
            divisors.push_back(prime);
            n /= prime;
        }
    }
    if (n > 1) {
        divisors.push_back(n);
    }

    return divisors;
}

vector<ll> ReadInputAsVector(int n) {
    vector<ll> v;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        v.push_back(a);
    }
    return v;
}

int FindPointWithMaxCoverage(vector<pair<int, int>> &ranges) {
    vector<pair<int, int>> endpoints;

    // Populate endpoints vector with left and right endpoints
    for (auto &range: ranges) {
        endpoints.push_back({range.first, 1});  // left endpoint
        endpoints.push_back({range.second, -1}); // right endpoint
    }

    // Sort endpoints based on values, breaking ties by giving priority to right endpoints
    sort(endpoints.begin(), endpoints.end(), [](const pair<int, int> &a, const pair<int, int> &b) {
        if (a.first == b.first) {
            return a.second > b.second;
        }
        return a.first < b.first;
    });

    int maxCoverage = 0;
    int pointWithMaxCoverage = -1;
    int coverage = 0;

    // Iterate through sorted endpoints and update coverage
    for (auto &endpoint: endpoints) {
        coverage += endpoint.second;
        if (coverage > maxCoverage) {
            maxCoverage = coverage;
            pointWithMaxCoverage = endpoint.first;
        }
    }

    return pointWithMaxCoverage;
}

bool StringComp(string a, string b) {
    if (a.size() > b.size()) return true;
    if (b.size() > a.size()) return false;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] > b[i]) return true;
        if (b[i] > a[i]) return false;
    }
    return false;
}

long long countAndMerge(vector<long long> &arr, int l, int m, int r) {
    int n1 = m - l + 1, n2 = r - m;

    vector<long long> left(n1), right(n2);
    for (int i = 0; i < n1; i++)
        left[i] = arr[i + l];
    for (int j = 0; j < n2; j++)
        right[j] = arr[m + 1 + j];

    long long res = 0;
    int i = 0, j = 0, k = l;
    while (i < n1 && j < n2) {
        if (left[i] <= right[j]) {
            arr[k++] = left[i++];
        } else {
            arr[k++] = right[j++];
            res += (n1 - i);
        }
    }

    while (i < n1)
        arr[k++] = left[i++];
    while (j < n2)
        arr[k++] = right[j++];

    return res;
}

long long countInv(vector<long long> &arr, int l, int r) {
    long long res = 0;
    if (l < r) {
        int m = (r + l) / 2;

        res += countInv(arr, l, m);
        res += countInv(arr, m + 1, r);

        res += countAndMerge(arr, l, m, r);
    }
    return res;
}

void InitMaxPrx(vector<ll> &maxPrx, vector<ll> &v) {
    for (int i = 0; i < v.size(); i++) {
        if (i == 0) {
            maxPrx.push_back(v[i]);
        } else {
            maxPrx.push_back(v[i] > maxPrx[i - 1] ? v[i] : maxPrx[i - 1]);
        }
    }
}

int largestPowerOf2Exponent(ll n) {
    return (n > 0) ? (31 - __builtin_clz(n)) : -1;
}

int smallestPowerOf2Exponent(ll n) {
    if (n == 0) return -1;
    return __builtin_ctz(n);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        ll l, r;
        cin >> l >> r;
        ll a = 0;
        ll b = 0;
        ll c = 0;
        int w = largestPowerOf2Exponent(r);
        int st = 0;
        for (int i = w; i >= 0; i--) {
            if (a + pow(2, i) - i < l) {
                a += pow(2, i);
                b += pow(2, i);
                c += pow(2, i);
            } else {
                if (a + pow(2, i) > r) continue;
                else {
                    st = i;
                    break;
                }
            }
        }
        a += pow(2, st);
        b = a -1;
        if(b-1 <=r && b-1>=l){
            c = b-1;
        }else{
            c = a+1;
        }
        cout << a << " " << b << " " << c << endl;
    }
    return 0;
}


Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <iomanip>
#include <string>

using namespace std;


using ll = long long;

class BIT {
private:
    vector<int> tree;

public:
    BIT(int size) : tree(size + 1, 0) {}

    // Update the BIT at index i by adding val
    void update(int i, int val) {
        for (++i; i < tree.size(); i += i & -i) {
            tree[i] += val;
        }
    }

    // Query the sum of elements in the BIT up to index i
    int query(int i) {
        int sum = 0;
        for (++i; i > 0; i -= i & -i) {
            sum += tree[i];
        }
        return sum;
    }
};

template<typename T>
void Print(const vector<T> &lst) {
    for (const T &element: lst) {
        cout << element;
    }
    cout << endl;
}

bool Intersects(int l, int r, int left, int right) {
    return (max(l, left) <= min(r, right));
}

long long ModularExponentiation(long long base, long long exponent, long long mod) {
    long long result = 1;
    base = base % mod;

    while (exponent > 0) {
        if (exponent % 2 == 1) {
            result = (result * base) % mod;
        }

        exponent = exponent >> 1; // equivalent to exponent /= 2
        base = (base * base) % mod;
    }
    return result;
}

ll Gcd(ll a, ll b) {
    while (b != 0) {
        long long temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

pair<double, double> GetIntersection(double l, double r, double li, double ri) {
    int intersectionLeft = max(l, li);

    int intersectionRight = min(r, ri);

    if (intersectionLeft <= intersectionRight) {
        return make_pair(intersectionLeft, intersectionRight);
    } else {
        return make_pair(-1, -1);
    }
}

ll Factorial(ll n) {
    if (n == 1 || n == 0) return 1;
    return n * Factorial(n - 1);
}

ll Lcm(ll a, ll b) {
    return a / Gcd(a, b) * b;
}

vector<int> SieveOfEratosthenes(int n) {
    vector<bool> prime(n + 1, true);

    for (int p = 2; p * p <= n; p++) {
        if (prime[p]) {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }

    vector<int> primes;
    for (int p = 2; p <= n; p++)
        if (prime[p])
            primes.push_back(p);

    return primes;
}

vector<int> PrimeDivisors(int n, vector<int> &primes) {
    vector<int> divisors;
    for (int prime: primes) {
        if (prime * prime > n) {
            break;
        }
        while (n % prime == 0) {
            divisors.push_back(prime);
            n /= prime;
        }
    }
    if (n > 1) {
        divisors.push_back(n);
    }

    return divisors;
}

vector<ll> ReadInputAsVector(int n) {
    vector<ll> v;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        v.push_back(a);
    }
    return v;
}

int FindPointWithMaxCoverage(vector<pair<int, int>> &ranges) {
    vector<pair<int, int>> endpoints;

    // Populate endpoints vector with left and right endpoints
    for (auto &range: ranges) {
        endpoints.push_back({range.first, 1});  // left endpoint
        endpoints.push_back({range.second, -1}); // right endpoint
    }

    // Sort endpoints based on values, breaking ties by giving priority to right endpoints
    sort(endpoints.begin(), endpoints.end(), [](const pair<int, int> &a, const pair<int, int> &b) {
        if (a.first == b.first) {
            return a.second > b.second;
        }
        return a.first < b.first;
    });

    int maxCoverage = 0;
    int pointWithMaxCoverage = -1;
    int coverage = 0;

    // Iterate through sorted endpoints and update coverage
    for (auto &endpoint: endpoints) {
        coverage += endpoint.second;
        if (coverage > maxCoverage) {
            maxCoverage = coverage;
            pointWithMaxCoverage = endpoint.first;
        }
    }

    return pointWithMaxCoverage;
}

bool StringComp(string a, string b) {
    if (a.size() > b.size()) return true;
    if (b.size() > a.size()) return false;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] > b[i]) return true;
        if (b[i] > a[i]) return false;
    }
    return false;
}

long long countAndMerge(vector<long long> &arr, int l, int m, int r) {
    int n1 = m - l + 1, n2 = r - m;

    vector<long long> left(n1), right(n2);
    for (int i = 0; i < n1; i++)
        left[i] = arr[i + l];
    for (int j = 0; j < n2; j++)
        right[j] = arr[m + 1 + j];

    long long res = 0;
    int i = 0, j = 0, k = l;
    while (i < n1 && j < n2) {
        if (left[i] <= right[j]) {
            arr[k++] = left[i++];
        } else {
            arr[k++] = right[j++];
            res += (n1 - i);
        }
    }

    while (i < n1)
        arr[k++] = left[i++];
    while (j < n2)
        arr[k++] = right[j++];

    return res;
}

long long countInv(vector<long long> &arr, int l, int r) {
    long long res = 0;
    if (l < r) {
        int m = (r + l) / 2;

        res += countInv(arr, l, m);
        res += countInv(arr, m + 1, r);

        res += countAndMerge(arr, l, m, r);
    }
    return res;
}

void InitMaxPrx(vector<ll> &maxPrx, vector<ll> &v) {
    for (int i = 0; i < v.size(); i++) {
        if (i == 0) {
            maxPrx.push_back(v[i]);
        } else {
            maxPrx.push_back(v[i] > maxPrx[i - 1] ? v[i] : maxPrx[i - 1]);
        }
    }
}

int largestPowerOf2Exponent(ll n) {
    return (n > 0) ? (31 - __builtin_clz(n)) : -1;
}

int smallestPowerOf2Exponent(ll n) {
    if (n == 0) return -1;
    return __builtin_ctz(n);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        ll l, r;
        cin >> l >> r;
        ll a = 0;
        ll b = 0;
        ll c = 0;
        int w = largestPowerOf2Exponent(r);
        int st = 0;
        for (int i = w; i >= 0; i--) {
            if (a + pow(2, i) - 1 < l) {
                a += pow(2, i);
                b += pow(2, i);
                c += pow(2, i);
            } else {
                if(i == w){
                    st = i;
                    break;
                }
                if (a + pow(2, i) > r) continue;
                else {
                    st = i;
                    break;
                }
            }
        }

        a += pow(2, st);
        b = a -1;
        if(b-1 <=r && b-1>=l){
            c = b-1;
        }else{
            c = a+1;
        }
        cout << a << " " << b << " " << c << endl;
    }
    return 0;
}