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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long
using namespace std; 

string calc(int n)
{
	string ans = "";
	while (n)
	{
		ans += to_string(n % 2);
		n >>= 1;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}
int recover(string str)
{
	int ans = 0ll;
	int now = 1;
	for (int i = str.size() - 1; i >= 0; -- i)
	{
		ans += (str[i] - '0')  * now;
		now <<= 1; 
	}
	return ans;
}
int sum(int a, int b, int c)
{
 	int ans = (a ^ b) + (b ^ c) + (c ^ a) ;
 	return ans ;
}
void solve()
{
	int ans1 = 0, ans2 = 0;
	int l, r; cin >> l >> r;
	int rr = r;
	int ll = l;
	int cnt1 = 0, cnt2= 0;
	string str1, str2;
	str1 = calc(l);
	str2 = calc(r);
//	cout << st2
	while (l) 
	{
		l >>= 1;
		++ cnt1;
	}
	while (r)
	{
		r >>= 1;
		++ cnt2;
	}
	int cnt = cnt2 - cnt1;
	while(cnt--) str1 = "0" + str1;
	string str_ans;
	int f = 0;
	int len = str2.size();
	int now = 0;
	for (int i = 0; i < str2.size(); ++ i)
	{
		if (str2[i] == '1') ++ now;
	}
//	cout << now << " " << len << '\n';
	if (ll == 0 && now == len)
	{
//		cout << "!!!!!!!\n";
		cout << 1 << " " << 2 << " " << rr - 3 << '\n';
		return;
	}
	for (int i = 0; i < len; ++ i)
	{
		if (!f && str1[i] == str2[i])
		{
			str_ans += str1[i];
		}
		else
		{
			f = 1;
			if (str1[i] == str2[i]) 
			{
				if (str1[i] == '0') str_ans += "1";
				else str_ans += "0";
			}
			else str_ans += str1[i];
		}
	}
//	cout << str1 << "\n"; cout << 6
//	cout << recover(str_ans)<<" "<< recover(str1)<<" "<< recover(str2) << '\n';
////	cout << str_ans << '\n';
//	
//	for (int i = 0; i < len; ++ i)
//	{
//		if (str_ans[i] > str2[i])  str_ans[i] = '0';
//		else if (str_ans[i] == str2[i]) continue;
//		else break;
//	}
//	ans1 = sum(recover(str_ans), recover(str1),recover(str1));
////	cout << ans1 << '\n';
//	string ans_str;
	if (str_ans > str1)
	{
		cout << recover(str1)<<" "<< recover(str_ans)<<" "<< recover(str2) << '\n';	
		return;
	}
	str_ans = "";
	f = 0;
//	// ++++++++++++++++++++++++++++++ //
	for (int i = 0; i < len; ++ i)
	{
		if (!f && str1[i] == str2[i])
		{
			str_ans += str1[i];
		}
		else
		{
			f = 1;
			if (str1[i] == str2[i]) 
			{
				if (str1[i] == '0') str_ans += "1";
				else str_ans += "0";
			}
			else str_ans += str2[i];
//			if (str2[i] == '1') ans_str += '0';
//			else ans_str += '1';
		}
	}
//	cout << str_ans << '\n';
	cout << recover(str1)<<" "<< recover(str_ans)<<" "<< recover(str2) << '\n';
//	for (int i = 0; i < len; ++ i)
//	{
//		if (ans_str[i] < str1[i])  str_ans[i] = '1';
//		else if (ans_str[i] == str1[i]) continue;
//		else break;
//	}
//	ans2 = sum(recover(ans_str), recover(str2), recover(str2));
//	
//	if (ans2 > ans1) cout << recover(ans_str)<<" "<< recover(str2)<<" "<< recover(str2) << '\n';
//	else cout<<recover(str_ans)<<" "<< recover(str1)<<" "<<recover(str1) << '\n';
	
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tes = 1;
	cin >> tes;
	while (tes--) solve();
	return 0;
}








Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std; 

string calc(int n)
{
	string ans = "";
	while (n)
	{
		ans += to_string(n % 2);
		n >>= 1;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}
int recover(string str)
{
	int ans = 0ll;
	int now = 1;
	for (int i = str.size() - 1; i >= 0; -- i)
	{
		ans += (str[i] - '0')  * now;
		now <<= 1; 
	}
	return ans;
}
int sum(int a, int b, int c)
{
 	int ans = (a ^ b) + (b ^ c) + (c ^ a) ;
 	return ans ;
}
void solve()
{
	int ans1 = 0, ans2 = 0;
	int l, r; cin >> l >> r;
	int rr = r;
	int ll = l;
	int cnt1 = 0, cnt2= 0;
	string str1, str2;
	str1 = calc(l);
	str2 = calc(r);
//	cout << st2
	while (l) 
	{
		l >>= 1;
		++ cnt1;
	}
	while (r)
	{
		r >>= 1;
		++ cnt2;
	}
	int cnt = cnt2 - cnt1;
	while(cnt--) str1 = "0" + str1;
	string str_ans;
	int f = 0;
	int len = str2.size();
	int now = 0;
	for (int i = 0; i < str2.size(); ++ i)
	{
		if (str2[i] == '1') ++ now;
	}
//	cout << now << " " << len << '\n';
	if (ll == 0 && now == len)
	{
//		cout << "!!!!!!!\n";
		cout << 1 << " " << 2 << " " << rr - 3 << '\n';
		return;
	}
	for (int i = 0; i < len; ++ i)
	{
		if (!f && str1[i] == str2[i])
		{
			str_ans += str1[i];
		}
		else
		{
			f = 1;
			if (str1[i] == str2[i]) 
			{
				if (str1[i] == '0') str_ans += "1";
				else str_ans += "0";
			}
			else str_ans += str1[i];
		}
	}
//	cout << str1 << "\n"; cout << 6
//	cout << recover(str_ans)<<" "<< recover(str1)<<" "<< recover(str2) << '\n';
////	cout << str_ans << '\n';
//	
//	for (int i = 0; i < len; ++ i)
//	{
//		if (str_ans[i] > str2[i])  str_ans[i] = '0';
//		else if (str_ans[i] == str2[i]) continue;
//		else break;
//	}
//	ans1 = sum(recover(str_ans), recover(str1),recover(str1));
////	cout << ans1 << '\n';
//	string ans_str;
	if (str_ans > str1)
	{
		cout << recover(str1)<<" "<< recover(str_ans)<<" "<< recover(str2) << '\n';	
		return;
	}
	str_ans = "";
	f = 0;
//	// ++++++++++++++++++++++++++++++ //
	for (int i = 0; i < len; ++ i)
	{
		if (!f && str1[i] == str2[i])
		{
			str_ans += str1[i];
		}
		else
		{
			f = 1;
			if (str1[i] == str2[i]) 
			{
				if (str1[i] == '0') str_ans += "1";
				else str_ans += "0";
			}
			else str_ans += str2[i];
//			if (str2[i] == '1') ans_str += '0';
//			else ans_str += '1';
		}
	}
//	cout << str_ans << '\n';
	if (str2 == str_ans)
	{
		cout << recover(str1)<<" " << recover(str1) + 1 << " " << recover(str2) << '\n';
		return ;	
	}
	cout << recover(str1)<<" "<< recover(str_ans)<<" "<< recover(str2) << '\n';
//	for (int i = 0; i < len; ++ i)
//	{
//		if (ans_str[i] < str1[i])  str_ans[i] = '1';
//		else if (ans_str[i] == str1[i]) continue;
//		else break;
//	}
//	ans2 = sum(recover(ans_str), recover(str2), recover(str2));
//	
//	if (ans2 > ans1) cout << recover(ans_str)<<" "<< recover(str2)<<" "<< recover(str2) << '\n';
//	else cout<<recover(str_ans)<<" "<< recover(str1)<<" "<<recover(str1) << '\n';
	
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tes = 1;
	cin >> tes;
	while (tes--) solve();
	return 0;
}