题解 AGC015D【A or...or B Problem】
题解 AGC015D【A or...or B Problem】
problem
从
solution
首先暴力怎么写呢?FWT。设序列
首先
考虑有了
考虑
除此之外没有别的数字,对
根据上面的构造,还可以发现这些可能的结果只需要两个数字或即可。所以 FWT 开平方就够了。
若认为高贵的 __builtin_clzll
是常数复杂度,则整个题的复杂度是常数。不用就是
code
#include <cstdio>
#include <vector>
#include <cstring>
#include <cassert>
#include <algorithm>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define debug(...) void(0)
#endif
#define bitclz __builtin_clzll
typedef long long LL;
LL getBit(int k) { return 1ll << k; }
bool conBit(LL x, int k) { return x & getBit(k); }
LL L, R;
int main() {
freopen("or.in", "r", stdin);
freopen("or.out", "w", stdout);
scanf("%lld%lld", &L, &R);
if (L == R) return puts("1"), 0;
int b = 63 - bitclz(L ^ R);
assert(conBit(R, b) && !conBit(L, b));
for (int i = b - 1; i >= 0; i--) if (conBit(R, i)) {
R |= getBit(i) - 1;
break;
}
LL U = (getBit(b) - 1) | (R >> b << b);
LL D = L | (R >> b << b);
if (R < D) printf("%lld\n", R - L + 1 + U - D + 1);
else printf("%lld\n", U - L + 1);
return 0;
}
本文来自博客园,作者:caijianhong,转载请注明原文链接:https://www.cnblogs.com/caijianhong/p/solution-agc015d.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具