题:https://codeforces.com/contest/1245/problem/F

分析:转化为:求区间内满足a&b==0的对数(解释见代码)

///求满足a&b==0在区间【l,r】的对数
///推导:区间[2l,2r]可由[l,r]乘3倍得来
///原因:*2我们可以看成事左移1位,那么这个位置上,对于俩个数来说
/////////可以取0,1 或1,0或0,0才依然满足 a&b==0这个题目条件
/////////这个公式可以用递归推导回溯计算,
/////////当我们回递归到区间为奇数的情况的时候,我们想办法让它变成偶数
/////////假设[a,b]中a是奇数,那么我们就把它弄成a+1,然后加上漏算的部分即可
/////////g(x,y)表示在区间[0,b]中和x满足题目条件的个数
/////////然后漏算的部分就是 (g(a,b)-g(a,a))*2
/////////b为奇数的情况也照样这样分析
/////////完 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll g(int a,int b){
ll ans=;
ll num=;
for(int i=;i<=b;i<<=){
if(i&b){
b^=i; if(!(a&b))
ans+=1ll<<num;
}
if(!(i&a)){///a在二进制下i位置为0的情况下,num就是计数这种情况的
num++;
}
}
return ans;
}
ll cal(int a,int b){
if(a==)
return *b-+cal(,b);
if(a==b)
return ;
ll ans=;
if(a&){///若左区间的值为奇数
ans+=(g(a,b)-g(a,a))*;///乘2是对数可以互换,然后这个就是剪掉区间缩成偶数时加上漏加的部分,类似于用前缀和算区间和
a++;
}
if(b&){///若右区间的值为偶数
ans+=(g(b-,b)-g(b-,a))*;
b--;
}
return ans+*cal(a/,b/);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int a,b;
scanf("%d%d",&a,&b);
printf("%I64d\n",cal(a,b+));
}
return ;
}

计算a^b==a+b在(l,r)的对数Codeforces Round #597 (Div. 2)的更多相关文章

  1. Codeforces Round #336 (Div. 2) B. Hamming Distance Sum 计算答案贡献+前缀和

    B. Hamming Distance Sum   Genos needs your help. He was asked to solve the following programming pro ...

  2. Codeforces Round #532 (Div. 2)- C(公式计算)

    NN is an experienced internet user and that means he spends a lot of time on the social media. Once ...

  3. Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize 概率dp

    B. Wizards and Huge Prize Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  4. Codeforces Round #538 (Div. 2) CTrailing Loves (or L'oeufs?)

    这题明白的意思就是求n!在b进制下的后缀零的个数. 即最大的n!%(b^k)==0的k的值.我们需要将如果要构成b这个数,肯定是由一个个质因子相乘得到的.我们只需要求出b的质因子,然后分析n!中可以组 ...

  5. Codeforces Round #377 (Div. 2) A. Buy a Shovel【暴力/口袋里面有无限枚 10 元和一枚 r 面值的硬币,问最少可以买多少把价值为 k 的铁铲】

    A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection

    C. An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 m ...

  7. Codeforces Round #574 (Div. 2) D1. Submarine in the Rybinsk Sea (easy edition) 【计算贡献】

    一.题目 D1. Submarine in the Rybinsk Sea (easy edition) 二.分析 简单版本的话,因为给定的a的长度都是定的,那么我们就无需去考虑其他的,只用计算ai的 ...

  8. Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp

    C. Kleofáš and the n-thlon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  9. Codeforces Round #330 (Div. 1) A. Warrior and Archer 贪心 数学

    A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594 ...

随机推荐

  1. POJ 1844:Sum ”滚动“数组

    Sum Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10494   Accepted: 6895 Description ...

  2. Linux(CENTOS7) NodeJs安装

    1.下载NodeJs 官网下载地址:http://nodejs.cn/download/ ​ 2.上传到linux系统 我这里上传到/disk/nodejs目录下面的,上传工具使用的xftp. ​ 3 ...

  3. Maven:A cycle was detected in the build path of project 'xxx'. The cycle consists of projects {xx}

    以下这个错误是在Eclipse中导入多个相互依赖的工程时出现的“循环依赖问题”:A cycle was detected in the build path of project 'xxx'. The ...

  4. CodeForces - 686D 【树的重心】

    传送门:http://codeforces.com/problemset/problem/686/D 题意:给你n个节点,其中1为根, 第二行给你2~n的节点的父亲节点编号. 然后是q个询问,求询问的 ...

  5. ZOJ 3299 线段树 离散化

    本来是个很简单的题目,难住我的主要是这么几点 1.它所有的点都是坐标,不是实际的砖块,1,3指的是1-2 2-3的砖块...后来就是用1 代表1-2 ,2代表2-3.....,这样的话,每次读入的数据 ...

  6. 在vSphere群集中配置EVC的注意事项

    原路径:https://blog.51cto.com/wangchunhai/2084434 个人觉得有一点写的有出入: 2 vCenter保存在本地存储中,无共享存储 中主机图片和描述信息有异常. ...

  7. ubuntu16.04 + Kdevelop + ROS开发和创建catkin_ws工作空间

    https://blog.csdn.net/p942005405/article/details/75715288 https://blog.csdn.net/LOVE1055259415/artic ...

  8. Linux--Centos7开机启动 mysql5.7.19

    参考:http://www.cnblogs.com/Anker/p/3551508.html

  9. openlayers基础用例

    http://weilin.me/ol3-primer/ch03/03-01.html#http://weilin.me/ol3-primer/ //地址http://openlayers.org/ ...

  10. Ubuntu的软件安装管理---dpkg与apt-*详解

    摘要:软件厂商先在他们的系统上面编译好了我们用户所需要的软件,然后将这个编译好并可执行的软件直接发布给用户安装.不同的 Linux 发行版使用不同的打包系统,一般而言,大多数发行版分别属于两大包管理技 ...