Codefroces 1245 F. Daniel and Spring Cleaning
考虑简单的容斥
设 $F(n,m)$ 表示 $a \in [1,n] , b \in [1,m]$ 的满足 $a+b=a \text{ xor } b$ 的数对的数量
那么答案即为 $F(r,r)-2F(l-1,r)+F(l-1,l-1)$
意思就是总方案减去 $a,b$ 至少一个数小于 $l$ 再加上 $a,b$ 都小于 $l$ 的方案
然后现在考虑求 $F$
首先显然 $a+b=a \text{ xor } b$ 意思就是二进制下不存在同时为 $1$ 的位
那么可以考虑简单的数位 $dp$,设 $f[i][0/1][0/1]$ 表示从高到低位填了 $i$ 位,$a$ 是否贴着上限 $n$ , $b$ 是否贴着上限 $m$ ,时的合法数对 $a,b$ 的方案数
那么转移就枚举下一位 $a$ 填的 $0$ 还是 $1$ , $b$ 填的 $0$ 还是 $1$ ,顺便保证一下满足限制就行了
代码参考:jiangly
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
ll solve(int n,int m)//注意此时的n,m是开区间
{
if(n<||m<) return ;
ll f[][][]; int p=;
f[p][][]=f[p][][]=f[p][][]=; f[p][][]=;
//0表示没贴着上限,1表示贴着上限
for(int i=;i>=;i--)
{
p^=; memset(f[p],,sizeof(f[p]));//滚动数组
for(int ln=;ln<=;ln++)
for(int lm=;lm<=;lm++)
for(int x=;x<=;x++)
for(int y=;x+y<=;y++)
if( ((!ln)||x<=((n>>i)&)) && ((!lm)||y<=((m>>i)&)) )
f[p][ln & ( x == ((n>>i)&) )][lm & ( y == ((m>>i)&) )] +=
f[p^][ln][lm];
}
return f[p][][];//不包括恰好等于n,m的情况
}
int main()
{
int T=read();
while(T--)
{
int l=read(),r=read();
printf("%lld\n",solve(r+,r+)-solve(l,r+)*+solve(l,l));//开区间,右端点集体+1
}
return ;
}
Codefroces 1245 F. Daniel and Spring Cleaning的更多相关文章
- [cf 1245 F] Daniel and Spring Cleaning
题意: 求区间$[l,r]$内有多少有序数对$(a,b)$满足$a+b=a\bigoplus b$. $l,r\leq 10^9$. 题解: 有用的就一句话: 求区间内一元组可以一维容斥,同理求二元组 ...
- Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp
F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...
- codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)
题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...
- CF1245F: Daniel and Spring Cleaning
CF1245F: Daniel and Spring Cleaning 题意描述: 给定区间\([L,R]\),其中 \((0\leq L,R\leq 10^9)\),问在区间内有多少数对\((x,y ...
- CodeForces - 1245F Daniel and Spring Cleaning (数位DP)
While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it ...
- Good Bye 2015 F - New Year and Cleaning
F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...
- Codeforces Round #597 (Div. 2)
A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...
- 并不对劲的CF1245E&F:Cleaning Ladders
CF1245 E. Hyakugoku and Ladders 题目大意 有一个10 \(\times\) 10的网格,你要按这样的路径行走: 网格中有一些单向传送门,每个传送门连接的两个格子在同一列 ...
- some problem
CF1257F Make Them Similar $solution:$ 折半搜索后考虑如何维护两个数组的和,可以将 $A$ 中每个数减 $A_1$ ,$B$ 中每个数被减 $B_1$ ,$map$ ...
随机推荐
- Thingsboard学习之一CentOS安装系统更新
首先安装好系统,查询到系统的IP地址后,使用Putty登入系统 更新系统 yum update 安装git yum install git 动图演示
- js修改Switchery复选框的状态
声明一个switchery插件,绑定到一个input上 js代码 var mySwitch = new Switchery($('#blacklist')[0], { size:"small ...
- jQuery插件fontIconPicker配合FontAwesome字体图标库的使用
同样先上效果图: 怎么样,是不是很好看,jquery fontIconPicker这个插件做的很不错,支持分类,搜索,还有分页功能,可以自定义分页,具体的使用方法我就不一介绍了,我只说一下如何使用fo ...
- The implementation of iterators in C# and its consequences (part 1) Raymond Chen
Likeanonymous methods, iterators in C# are very complex syntactic sugar. You could do it all yoursel ...
- Linux shell脚本 (十二)case语句
case语句 case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构. case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case ...
- vue项目中 favicon.ico不能正确显示的问题
方法一:修改index.html文件 <link rel="shortcut icon" type="image/x-icon" href="f ...
- websphere 英文版部署(更新)项目【我】
websphere 部署(更新)项目 首先在控制台页面依次点左侧,打开应用配置页面: 然后在右侧勾选我们要重新部署的项目,首先点上面的 停止 按钮,等项目停止后,再勾选项目,点上面的 更新 按钮(如 ...
- osg qt fbx
void TeslaManage::loadModelFile(QString &filename) { file_node = osgDB::readNodeFile(std::string ...
- Oracle SQL 脚本跟踪
NC Oracle SQL 脚本跟踪 脚本: select * from v$sqlarea a and a.LAST_ACTIVE_TIME >= to_date( '2013-02-21 1 ...
- ElasticSearch——数据建模最佳实践
如何建模 mapping 设计非常重要,需要从两个维度进行考虑: 功能:搜索.排序.聚合 性能:存储的开锁.内存的开销.搜索的性能 mapping 注意事项: 加入新字段很容易(必要时需要 updat ...