题意:

求区间$[l,r]$内有多少有序数对$(a,b)$满足$a+b=a\bigoplus b$。

$l,r\leq 10^9$。

题解:

有用的就一句话:

求区间内一元组可以一维容斥,同理求二元组可以二维容斥,三元组可以三维容斥……

我tm原来居然不知道,佛了。

然后数位dp就完事了。

代码:

#include<bits/stdc++.h>
#define maxn 55
#define maxm 500005
#define inf 0x7fffffff
#define ll long long using namespace std;
ll dp[maxn][][][][],d1[maxn],d2[maxn]; inline ll read(){
ll x=,f=; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-;
for(;isdigit(c);c=getchar()) x=x*+c-'';
return x*f;
} inline ll dfs(ll now,int t1,int t2,int q1,int q2){
if(now==-) return ;
if(dp[now][t1][t2][q1][q2]!=-) return dp[now][t1][t2][q1][q2];
int u1=t1?d1[now]:,u2=t2?d2[now]:; ll res=;
for(int i=;i<=u1;i++)
for(int j=;j<=u2;j++){
if(i== && j==) continue;
int nt1=t1&&(i==u1);
int nt2=t2&&(j==u2);
int nq1=q1||(i==);
int nq2=q2||(j==);
res+=dfs(now-,nt1,nt2,nq1,nq2);
}
dp[now][t1][t2][q1][q2]=res;
return res;
} inline ll calc(ll x,ll y){
if(x< || y<) return ;
memset(dp,-,sizeof(dp));
for(ll i=;i<=;i++) d1[i]=((x>>i)&);
for(ll i=;i<=;i++) d2[i]=((y>>i)&);
return dfs(,,,,);
} int main(){
ll T=read();
while(T--){
ll l=read(),r=read();
printf("%I64d\n",calc(r,r)-*calc(l-,r)+calc(l-,l-));
}
return ;
}

F

[cf 1245 F] Daniel and Spring Cleaning的更多相关文章

  1. 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, ...

  2. 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 ...

  3. codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)

    题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...

  4. CF1245F: Daniel and Spring Cleaning

    CF1245F: Daniel and Spring Cleaning 题意描述: 给定区间\([L,R]\),其中 \((0\leq L,R\leq 10^9)\),问在区间内有多少数对\((x,y ...

  5. CodeForces - 1245F Daniel and Spring Cleaning (数位DP)

    While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it ...

  6. CF 633 F. The Chocolate Spree 树形dp

    题目链接 CF 633 F. The Chocolate Spree 题解 维护子数答案 子数直径 子数最远点 单子数最长直径 (最长的 最远点+一条链) 讨论转移 代码 #include<ve ...

  7. Good Bye 2015 F - New Year and Cleaning

    F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...

  8. CF #271 F Ant colony 树

    题目链接:http://codeforces.com/contest/474/problem/F 一个数组,每一次询问一个区间中有多少个数字可以整除其他所有区间内的数字. 能够整除其他所有数字的数一定 ...

  9. CF 494 F. Abbreviation(动态规划)

    题目链接:[http://codeforces.com/contest/1003/problem/F] 题意:给出一个n字符串,这些字符串按顺序组成一个文本,字符串之间用空格隔开,文本的大小是字母+空 ...

随机推荐

  1. vue-skeleton-webpack-plugin骨架屏与page-skeleton-webpack-plugin骨架屏生成插件

    vue-skeleton-webpack-plugin与page-skeleton-webpack-plugin使用 插件github地址:https://github.com/lavas-proje ...

  2. vue+elementui项目打包后样式变化问题

    博主刚刚解决了index.html空白问题,刚打开项目页面又发现了样式出现了大问题,样式与开发版本有很大不同,有些样式没有生效.利用搜索引擎,找到了问题所在以及解决办法:main.js中的引入顺序决定 ...

  3. Tomcat 9 管理界面配置

    Tomcat9 在conf/tomcat_user.xml配置后,还是出现如下错误 然后修改tomcat9/webapps/manager/META-INF的context.xml文件

  4. Java类成员初始化顺序

    类中包含7中成员:1.静态变量 static2.final静态常量 final static3.静态代码块 static{}  //多个代码块顺序执行 4.普通变量5.普通代码块 {}  //多个代码 ...

  5. how to transfer your linux to new work environment

    tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --ex ...

  6. SpringCloud 微服务中 @Async 注解自定义线程池 引发的aop 问题

    背景 在 使用springCloud 的@Async注解来做异步操作时,想自定义其线程池. 引发问题 自定义完线程池后,发现代码里并没有使用自定义线程池里的线程,于是新建一个demo工程,一样的配置代 ...

  7. server computer (实验室移动服务器环境)

    star@xmatrix:~$ lshwWARNING: you should run this program as super-user.xmatrix                       ...

  8. SpringBoot入门-JPA(三)

    什么是JPA JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. pom.xml <par ...

  9. [ERROR] ionic-app-scripts has unexpectedly closed (exit code 1).

    这个错误是因为缺失 '@ionic/app-scripts',只要安装 '@ionic/app-scripts' 即可. 解决方法:npm install @ionic/app-scripts@lat ...

  10. 【451】python 同一行打印进度条

    参考:Python3 Print 同一行打印显示进度条效果 参考:\r\n, \r and \n what is the difference between them? [duplicate] 参考 ...