Bitwise And Queries

Time limit: 1500 ms
Memory limit: 128 MB

You are given QQ queries of the form a\ b\ xa b x. Count the number of values yy such that a \leq y \leq ba≤y≤b and x\ \& \ y = xx & y=x, where we denote by \&& the bitwise and operation.

Standard input

The first line contains a single integer QQ.

Each of the following QQ lines contains three integers a\ b\ xa b x, representing a query.

Standard output

Output QQ lines, each containing a single integer representing the answer to a query.

Constraints and notes

  • 1 \leq Q \leq 10^51≤Q≤10​5​​
  • 1 \leq a \leq b \leq 10^{18}1≤a≤b≤10​18​​
  • 0 \leq x \leq 10^{18}0≤x≤10​18​​
Input Output
4
1 10 3
5 10 0
1 63 7
32 100 32
2
6
8
37
 

x&y==x,说明x二进制表示上,有1的地方,y也要有1,是0的地方,y可以是0或者1,记忆化瞎几把搜一下就行了,每次可以选择的有0或1,再判断一下能否取0或1。

lr表示此时这个位置y能否取任意数,只要前面x为0,y为1时,递归选0的话,就说明y后面的数可以任意取了,因为前面有1选了0,那后面无论选什么都不可能超过上界了。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = ;
const int inf = 0x3f3f3f3f;
const int mod = ;
LL dp[][];
int A[],X[];
LL solve(int cur,int lr){
if(cur == )return ;
if(dp[cur][lr] != -)return dp[cur][lr];
if(lr){
if(A[cur]){
return dp[cur][lr] = solve(cur + ,lr);
}
else {
return dp[cur][lr] = * solve(cur + ,lr);
}
}
else {
if(A[cur]){
if(X[cur])return dp[cur][lr] = solve(cur + ,lr);
else return dp[cur][lr] = ;
}
else {
if(X[cur])return dp[cur][lr] = solve(cur+,) + solve(cur+,lr);
else return dp[cur][lr] = solve(cur+,lr);
}
}
}
void print(int *x){
for(int i = ; i < ; i++)
printf("%d",x[i]);
puts("");
}
int main(){
#ifdef local
freopen("in", "r", stdin);
#endif
int T;
scanf("%d",&T);
while(T--){
LL x,y,a;
scanf("%lld%lld%lld",&x,&y,&a);
x--;
for(int i = ; i < ; i++){
A[i] = a & ;
a >>= ;
}
reverse(A,A+);
// print(A);
for(int i = ; i < ; i++){
X[i] = x & ;
x >>= ;
}
reverse(X,X+);
// print(X);
memset(dp,-,sizeof dp);
LL res = solve(,);
for(int i = ; i < ; i++){
X[i] = y & ;
y >>= ;
}
reverse(X,X+);
// print(X);
memset(dp,-,sizeof dp);
res = solve(,) - res;
printf("%lld\n",res);
}
}

Bitwise And Queries的更多相关文章

  1. CF-1451 E Bitwise Queries 异或 交互题

    E - Bitwise Queries 传送门 题意 有一组序列,长度为 \(n(4\le n \le 2^{16})\),且 \(n\) 为 2 的整数次幂,序列中数值范围为 [0,n-1], 每次 ...

  2. 【做题记录】CF1451E2 Bitwise Queries (Hard Version)

    CF1451E2 Bitwise Queries (Hard Version) 题意: 有 \(n\) 个数( \(n\le 2^{16}\) ,且为 \(2\) 的整数次幂,且每一个数都属于区间 \ ...

  3. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  4. 实践 HTML5 的 CSS3 Media Queries

    先来介绍下 media,确切的说应该是 CSS media queries(CSS 媒体查询),媒体查询包含了一个媒体类型和至少一个使用如宽度.高度和颜色等媒体属性来限制样式表范围的表达式.CSS3 ...

  5. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  6. SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问

    delphi ado 跨数据库访问 语句如下 ' and db = '帐套1' 报错内容是:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATE ...

  7. CSS3 Media Queries 实现响应式设计

    在 CSS2 中,你可以为不同的媒介设备(如屏幕.打印机)指定专用的样式表,而现在借助 CSS3 的 Media Queries 特性,可以更为有效的实现这个功能.你可以为媒介类型添加某些条件,检测设 ...

  8. 使用CSS3 Media Queries实现网页自适应

    原文来源:http://webdesignerwall.com 翻译:http://xinyo.org 当今银屏分辨率从 320px (iPhone)到 2560px (大屏显示器)或者更大.人们也不 ...

  9. SQL Queries from Transactional Plugin Pipeline

    Sometimes the LINQ, Query Expressions or Fetch just doesn't give you the ability to quickly query yo ...

随机推荐

  1. (删)Java线程同步实现一:synchronzied和wait()/notify()

    上面文章(2.Java多线程总结系列:Java的线程控制实现)讲到了如何对线程进行控制,其中有一个是线程同步问题.下面我们先来看一个例子: 1.一个典型的Java线程安全例子 package com. ...

  2. hive 动态分区数设置

    当对hive分区未做设置时,报错如下: Caused by: org.apache.hadoop.hive.ql.metadata.HiveFatalException: [Error 20004]: ...

  3. Statistical Models and Social Science

    1.1 Statistical Models and Social Reality KEY: complex society v.s statistical models relationship,d ...

  4. app专项测试自动化测试方法思路与实现

    秉着个人意愿打算把python+rf接口自动进行彻底结束再做些其它方面的输出~但事与愿违,但领导目前注重先把专项测试方面完成,借此,先暂停python+rf(主要是与Jenkins集成+导入DB+微信 ...

  5. SpringCloud网关ZUUL集成consul

    最近一直在搞基于springcloud的微服务开发,为了不限定微服务开发语言,服务发现决定采用consul不多说上代码 pom文件 <project xmlns="http://mav ...

  6. phpcms 笔记

      首先是要把首页分为三个部分  : 导航部分 .尾部和首页中间部分  用了三个不同的文件 header.html ; index.html; footer.html   在使用phpcms之前 首先 ...

  7. 开始使用ansible

    ansible是一个设计巧妙,功能强大,安全,使用简单的IT自动化运维工具.它可以实现统一配置管理,持续部署,流程编排等. 目前控制主机必须是linux,被控制主机可以是linux,类UNIX和win ...

  8. netcore实践:跨平台动态加载native组件

    缘起netcore框架下实现基于zmq的应用. 在.net framework时代,我们进行zmq开发由很多的选择,比较常用的有clrzmq4和NetMQ. 其中clrzmq是基于libzmq的Int ...

  9. Evermoney -- 重新定义印象笔记编辑体验

    关于印象笔记 知识管理工具自己也算用过很多了,国内的有道,为知:国外的onenote.因为印象笔记的裁剪以及搜索功能太强大了,所以最后还是选择用印象笔记了.不过印象笔记这个公司确实态度有点不敢恭维,关 ...

  10. [ext4]04 磁盘布局 - Meta Block Groups

    Meta Block Groups,可以翻译为元块组集. 如果不采用Meta Block Groups特性,在每个冗余备份的超级块的后面是一个完整的(包含所有块组描述符的)块组描述符表的备份.如前所述 ...