Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#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;
using namespace chrono;

#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define vb vector<bool>
#define int long long
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define s string
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define cneg cout << -1 << endl;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

// Read this whenever you feel like giving up
// Its not you versus the however many people giving the contest
// Its you versus the problem
// You are not competing with anyone
// You are competing with yourself
// You are trying to be better than you were yesterday
// You are trying to be better than you were 5 minutes ago
// You are trying to be better than you were 5 seconds ago
// So keep going
// Keep pushing
// and keep trying until you finish the problem

void print(vi a)
{
  for (int i = 0; i < a.size(); i++)
  {
    cout << a[i] << " ";
  }
  cout << endl;
}

void solve()
{
  int l, r;
  cin >> l >> r;

  vi lb(32, 0), rb(32, 0);

  for(int i = 0; i < 32; i++)
  {
    if((1<<i)&l) lb[32 - i - 1] = 1;
    if((1<<i)&r) rb[32 - i - 1] = 1;
  }

  vi mb(32, 0);

  bool diff = false;
  int idx = 0;
  for(int i = 0; i < 32; i++)
  {
    if(lb[i] == rb[i] && !diff)
    {
      mb[i] = lb[i];
      idx = i + 1;
    }
    else
    {
      diff = true;
    }
  }
  
  int l_i = 0;
  int m_i = 0;
  int r_i = 0;
  
  for(int i = 31; i >= idx; i--)
  {
    if(lb[i] == rb[i])
    {
      if(lb[i] == 1) mb[i] = 0;
      else mb[i] = 1;
    }
    else
    {
      if(lb[i] == 0)
      {
        if(m_i >= r_i)
        {
          mb[i] = 0;
        }
        else mb[i] = 1;
      }
      else
      {
        mb[i] = 1;
      }
    }
    
    if(lb[i]) l_i |= (1<<(32-i-1));
    if(rb[i]) r_i |= (1<<(32-i-1));
    if(mb[i]) m_i |= (1<<(32-i-1));
  }

  for(int i = idx - 1; i >= 0; i--)
  {
    if(lb[i]) l_i |= (1<<(32-i-1));
    if(rb[i]) r_i |= (1<<(32-i-1));
    if(mb[i]) m_i |= (1<<(32-i-1));
  }
  
  // print(lb);
  // print(mb);
  // print(rb);

  if(m_i == l_i) m_i++;
  if(m_i == r_i) m_i--;

  cout << l_i << " " << m_i << " " << r_i;
  
  cout << endl;
}

#undef int
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  fastio();

  auto start1 = high_resolution_clock::now();

  int t = 1;
  cin >> t;

  while (t--)
  {
    solve();
  }

  auto stop1 = high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stop1 - start1);
#ifndef ONLINE_JUDGE
  cerr << "Time: " << duration.count() << " ms" << endl;
#endif

  return 0;
}


// Code with passion, conquer with persistence. Keep coding, keep winning.


// ALL SNIPPETS
// qa: Base template
// ia: Input array
// ye: yes
// no: no
// os: ordered set
// bp: Binary exponentiation
// bpm: Binary exponentiation with modulo
// bsmx: Binary search for max
// bsmn: Binary search for min
// quad: Quadratic Equation
// segtree: STree class snippet
// ig: input graph
// in: input n
// inm: input n m
// constructpath: For loop to construct path snippet
// matrixexpo: Matrix class and exponentiation
// combo: nCr
// modinv: Mod Inverse
// dijkstra: Dijkstra algo for sparse graph where m ~= n, T.C = O(nlogn + m)
// floydwarshall: floyd warshall dist all pairs
// dgcycle: Directed Cycle check
// ugcycle: UnDirected Cycle check