C
在 [ l r ] 中选取三个数,最大化 两两异或的和。
A^B + A^C + B ^ C
输出 A B C 这三个数。
首先来考虑一下 怎样使得异或的和最大。我们按位考虑
有四种情况 000 001 011 111
当有一个1 和两个1 的时候,这一位的贡献达到最大值 2 *一定的次幂
我们从L R 第一个不同的位置开始考虑
a 相同的前缀 0 1 1 1 1 1 …
b 相同的前缀 1 0 0 0 0 0 …
当我们这么构造之后,已经保证了每一位都有一个1 了,此时c在这一位的情况是什么,不会影响我的异或和的值了。
所以c 可以是不同于 a b 的任何一个值。
这里直接假设 c 是 l .但如果ans-1==l ,因为我们肯定有三个数,所以c可以取ans+1
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
#define int long long
int read()
{
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch))
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch))
{
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
void solve()
{
int l ,r;cin>>l>>r;
int k=__lg(r);
int ans=0;
// 把他们的公共前缀搞出来
while((r>>k&1)==(l>>k&1))ans+=(r>>k&1)<<k,k--;
ans+=1<<k;
cout<<ans<<" "<<ans-1<<" ";
cout<<(ans-1==l?ans+1:l)<<"\n";
}
signed main()
{
std::cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin>>t;
while (t--)
{
solve();
}
return 0;
}