99732024-03-22 14:09:41111Xorcpp17Time limit exceeded 0/100166ms4712 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)){
					x=ax,y=ay,z=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("be1.txt","r",stdin);
//	freopen("out.txt","w",stdout);
#endif
	for(int l=0;l<=100;l++){
		for(int r=l+2;r<=100;r++){
			int x,y,z;
			if(solve(l,r,x,y,z)!=solve2(l,r,x,y,z)){
				cout<<l<<' '<<r<<'\n';
				cout<<solve(l,r,x,y,z)<<" : "<<x<<' '<<y<<' '<<z<<'\n';
				cout<<solve2(l,r,x,y,z)<<" : "<<x<<' '<<y<<' '<<z<<'\n';
				exit(1);
			}
		}
	}
	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
base0/100
1Time limit exceeded0/0152ms1804 KiB
2Time limit exceeded0/0163ms2308 KiB
3Time limit exceeded0/5159ms2376 KiB
4Time limit exceeded0/5158ms2588 KiB
5Time limit exceeded0/5158ms2672 KiB
6Time limit exceeded0/5157ms2820 KiB
7Time limit exceeded0/5159ms3188 KiB
8Time limit exceeded0/5149ms2928 KiB
9Time limit exceeded0/5162ms3252 KiB
10Time limit exceeded0/5136ms3144 KiB
11Time limit exceeded0/5166ms3692 KiB
12Time limit exceeded0/5144ms3628 KiB
13Time limit exceeded0/5152ms3656 KiB
14Time limit exceeded0/6157ms3664 KiB
15Time limit exceeded0/6152ms3668 KiB
16Time limit exceeded0/6158ms3664 KiB
17Time limit exceeded0/6150ms3668 KiB
18Time limit exceeded0/7137ms3816 KiB
19Time limit exceeded0/7165ms4256 KiB
20Time limit exceeded0/7165ms4712 KiB