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

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while(t--){
        unsigned int l, r;
        cin >> l >> r;
        // We are guaranteed that r - l > 1 so there are at least 3 numbers.
 
        // Collect candidate numbers from near the ends.
        // (Using a total of up to 32 candidates is plenty.)
        vector<unsigned int> cand;
        // Take the first 16 numbers from l (or all if fewer than 16 available)
        unsigned int cntLow = min((unsigned int)16, r - l + 1);
        for (unsigned int x = l; x < l + cntLow; x++){
            cand.push_back(x);
        }
        // Take the last 16 numbers (again, adjust if the interval is small)
        unsigned int cntHigh = min((unsigned int)16, r - l + 1);
        unsigned int startHigh = (r >= cntHigh - 1 ? r - (cntHigh - 1) : l);
        for (unsigned int x = startHigh; x <= r; x++){
            cand.push_back(x);
        }
        // Remove duplicates (if the interval is very small, the two groups might overlap)
        sort(cand.begin(), cand.end());
        cand.erase(unique(cand.begin(), cand.end()), cand.end());
 
        // Try all triples among the candidate numbers.
        // (Since the candidate set is small, a triple–loop is fast.)
        unsigned long long bestVal = 0;
        unsigned int ansA = l, ansB = l, ansC = l;
        int n = cand.size();
        for (int i = 0; i < n; i++){
            for (int j = i+1; j < n; j++){
                for (int k = j+1; k < n; k++){
                    unsigned int a = cand[i], b = cand[j], c = cand[k];
                    // Compute the team independence
                    unsigned int xor_ab = a ^ b;
                    unsigned int xor_bc = b ^ c;
                    unsigned int xor_ac = a ^ c;
                    unsigned long long sum = (unsigned long long)xor_ab + xor_bc + xor_ac;
                    if(sum > bestVal){
                        bestVal = sum;
                        ansA = a; ansB = b; ansC = c;
                    }
                }
            }
        }
 
        cout << ansA << " " << ansB << " " << ansC << "\n";
    }
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
// We define -infinity (for impossible states)
const ll MINF = -1e18;
 
// Global arrays to store the bit–representation of l and r.
// For pos = 30 down to 0.
int Lbits[32], Rbits[32];
 
// We will use a 4-dimensional DP state:
//   dp[pos][lbMask][ubMask][diffMask]
// where:
//   - pos: current bit position we are processing (from 30 down to 0).
//   - lbMask: a 3–bit mask (bits 0–2) for the three numbers; for a given number i, 
//             bit i = 1 means that in some higher bit the number already exceeded l.
//   - ubMask: similarly, bit i = 1 means the number is already below r.
//   - diffMask: a 3–bit mask representing which pairs of numbers have already been made different:
//             bit0: numbers 0 and 1 differ; bit1: numbers 0 and 2 differ; bit2: numbers 1 and 2 differ.
 
// Our dp value is the maximum additional sum (from the current pos downwards) that can be obtained
// from a valid assignment (or MINF if no valid assignment exists).
 
int dp[33][8][8][8];
bool vis[33][8][8][8];
 
// For reconstruction we store our decision in each state.
struct Choice {
    int nb0, nb1, nb2;  // chosen bits at this pos for numbers 0,1,2
    int nlmask, nubmask, ndmask; // new masks after this bit
    bool used;
};
 
Choice choiceRec[33][8][8][8];
 
// The recursive DP function.
// pos: current bit (from 30 down to 0); when pos < 0 we are done.
// lbMask, ubMask, diffMask: as explained above.
int rec (int pos, int lbMask, int ubMask, int diffMask) {
    if(pos < 0){
        // At the end, we require that all three pairs are different.
        if(diffMask == 7) return 0;
        else return MINF;
    }
    if(vis[pos][lbMask][ubMask][diffMask]) return dp[pos][lbMask][ubMask][diffMask];
    vis[pos][lbMask][ubMask][diffMask] = true;
    int best = MINF;
    Choice bestChoice;
    bestChoice.used = false;
    // There are 8 possible assignments for the three bits at this position.
    for(int mask = 0; mask < 8; mask++){
        // Extract bits for numbers 0,1,2.
        int b0 = (mask >> 0) & 1;
        int b1 = (mask >> 1) & 1;
        int b2 = (mask >> 2) & 1;
 
        bool valid = true;
        // Check for each number if our choice is allowed by the bounds.
        for(int i = 0; i < 3; i++){
            int chosen = (mask >> i) & 1;
            int lbBit = Lbits[pos];
            int rbBit = Rbits[pos];
            // If we haven’t yet exceeded l for number i, then we must choose a bit >= Lbits[pos].
            if( ((lbMask >> i) & 1) == 0 ){
                if(chosen < lbBit) { valid = false; break; }
            }
            // Similarly, if we haven’t yet gone below r for number i, then chosen bit must be <= Rbits[pos].
            if( ((ubMask >> i) & 1) == 0 ){
                if(chosen > rbBit) { valid = false; break; }
            }
        }
        if(!valid) continue;
 
        // Update the lower-bound and upper-bound flags for each number.
        int newLB = 0, newUB = 0;
        for(int i = 0; i < 3; i++){
            int chosen = (mask >> i) & 1;
            int lbBit = Lbits[pos], rbBit = Rbits[pos];
            // For lower-bound: if already above l then remain; otherwise, if chosen > Lbits[pos] then we are now above.
            if((lbMask >> i) & 1) newLB |= (1 << i);
            else {
                if(chosen > lbBit) newLB |= (1 << i);
            }
            // For upper-bound: similarly.
            if((ubMask >> i) & 1) newUB |= (1 << i);
            else {
                if(chosen < rbBit) newUB |= (1 << i);
            }
        }
 
        // Update the diff flags: for each pair, if the bits chosen differ then mark that pair as “different.”
        int newDiff = diffMask;
        if(b0 != b1) newDiff |= 1;       // pair (0,1)
        if(b0 != b2) newDiff |= 2;       // pair (0,2)
        if(b1 != b2) newDiff |= 4;       // pair (1,2)
 
        // The contribution at this bit is 2*(1<<pos) if not all three bits are equal.
        int contrib = 0;
        if(!( (b0==b1) && (b1==b2) ))
            contrib = 2 * (1 << pos);
 
        int nxt = rec(pos-1, newLB, newUB, newDiff);
        if(nxt == MINF) continue;
        int total = contrib + nxt;
        if(total > best){
            best = total;
            bestChoice.nb0 = b0;
            bestChoice.nb1 = b1;
            bestChoice.nb2 = b2;
            bestChoice.nlmask = newLB;
            bestChoice.nubmask = newUB;
            bestChoice.ndmask = newDiff;
            bestChoice.used = true;
        }
    }
    dp[pos][lbMask][ubMask][diffMask] = best;
    choiceRec[pos][lbMask][ubMask][diffMask] = bestChoice;
    return best;
}
 
// Reconstruct the three numbers from the DP decisions.
void reconstruct(int pos, int lbMask, int ubMask, int diffMask, ll &a, ll &b, ll &c) {
    if(pos < 0) return;
    Choice ch = choiceRec[pos][lbMask][ubMask][diffMask];
    // Append the chosen bits (we are processing from MSB to LSB).
    a = (a << 1) | ch.nb0;
    b = (b << 1) | ch.nb1;
    c = (c << 1) | ch.nb2;
    reconstruct(pos-1, ch.nlmask, ch.nubmask, ch.ndmask, a, b, c);
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t; 
    cin >> t;
    while(t--){
        unsigned int L, R;
        cin >> L >> R;
        // It is given that r-l > 1 so there are at least 3 numbers.
 
        // Fill in the bit arrays for positions 30 down to 0.
        for (int pos = 30; pos >= 0; pos--){
            Lbits[pos] = (L >> pos) & 1;
            Rbits[pos] = (R >> pos) & 1;
        }
 
        // Clear the memo arrays.
        memset(vis, 0, sizeof(vis));
 
        int best = rec(30, 0, 0, 0);
        // (We do not really need the best sum; we only need a triple achieving it.)
 
        ll a = 0, b = 0, c = 0;
        reconstruct(30, 0, 0, 0, a, b, c);
 
        // Output the triple.
        cout << a << " " << b << " " << c << "\n";
    }
    return 0;
}