99752024-03-22 14:17:36111Xorcpp17Accepted 100/10046ms4348 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int solve(int l,int r,int&x,int&y,int&z){
	x=l,y=l+1,z=l+2;
	int ox=0,oy=0,oz=0;
	for(int i=62;i>=0;i--){
		int a=l>>i&1,b=r>>i&1;
		if(a!=b){
			if(r>=ox+(b<<i)+2){
				int ax=ox|1ll<<i;
				int ay=oy|1ll<<i;
				int az=oz|1ll<<i;
				for(int j=i-1;j>=0;j--){
					int b=r>>j&1;
					if(ax!=ay){
						ax|=1ll<<j;
					}
					else if(b){
						ay|=1ll<<j;
					}
				}
				if((ax^ay^az)>(x^y^z)){
					y=ax,z=ay,x=az;
				}
			}
			if(l<=ox+(b<<i)-2){
				int ax=ox;
				int ay=oy;
				int az=oz|1ll<<i;
				for(int j=i-1;j>=0;j--){
					int b=l>>j&1;
					if(ax!=ay){
						ax|=1ll<<j;
					}
					else if(!b){
						ay|=1ll<<j;
					}
					else{
						ax|=1ll<<j;
						ay|=1ll<<j;
					}
				}
				if((ax^ay^az)>(x^y^z)){
					x=ax,y=ay,z=az;
				}
			}
			break;
		}
		ox|=a<<i;
		oy|=a<<i;
		oz|=a<<i;
	}
	return x^y^z;
}

int solve2(int l,int r,int&x,int&y,int&z){
	x=0,y=0,z=0;
	int ax,ay,az;
	for(ax=l;ax<=r;ax++){
		for(ay=ax+1;ay<=r;ay++){
			for(az=ay+1;az<=r;az++){
				if((ax^ay^az)>(x^y^z)){
					x=ax,y=ay,z=az;
				}
			}
		}
	}
	return x^y^z;
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef CB
	freopen("be2.txt","r",stdin);
//	freopen("out.txt","w",stdout);
#endif
	int T;
	cin>>T;
	while(T--){
		int L,R;
		cin>>L>>R;
		int x,y,z;
		solve(L,R,x,y,z);
		cout<<x<<' '<<y<<' '<<z<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms1896 KiB
2Accepted0/07ms2324 KiB
3Accepted5/53ms2304 KiB
4Accepted5/53ms2528 KiB
5Accepted5/53ms2744 KiB
6Accepted5/52ms2812 KiB
7Accepted5/54ms3096 KiB
8Accepted5/54ms3240 KiB
9Accepted5/56ms3364 KiB
10Accepted5/57ms3460 KiB
11Accepted5/510ms3364 KiB
12Accepted5/510ms3764 KiB
13Accepted5/519ms4116 KiB
14Accepted6/628ms4216 KiB
15Accepted6/637ms4240 KiB
16Accepted6/646ms4224 KiB
17Accepted6/646ms4348 KiB
18Accepted7/77ms4212 KiB
19Accepted7/746ms4320 KiB
20Accepted7/746ms4344 KiB