题解 AT_arc129_a [ARC129A] Smaller XOR
NightmareAlita · · 题解
简要题意
给你三个数
策略分析
我们考虑异或运算的性质,当某一位为
上面我们讨论了能够得到
参考代码
#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
namespace SHAWN {
LL n, l, r, ans;
int work()
{
cin >> n >> l >> r;
for (int i = 0; (1ll << i) <= n; ++i) {
LL xl = 1ll << i, xr = (xl << 1) - 1;
if (!(xl & n)) { continue; }
LL edgel = max(l, xl), edger = min(r, xr);
ans = max(ans, ans + edger - edgel + 1);
}
cout << ans << '\n';
return 0;
}
}
signed main() {
ios :: sync_with_stdio(false);
cin.tie(nullptr);
return SHAWN :: work();
}