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. 老李分享:DBA

    poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-845052 ...

  2. input是否checked与使用jquery的attr或prop方法无关

    最近在项目中有这样一个需求,用户在下单时可以选择优惠券,也可取消选择,并且可以多次选择,取消. 这是一个典型的input标签checked功能,博主使用radio元素实现此需求,但是优惠券只能选中,不 ...

  3. Struts2基础学习(三)—Result和数据封装

    一.Result      Action处理完用户请求后,将返回一个普通的字符串,整个普通字符串就是一个逻辑视图名,Struts2根据逻辑视图名,决定响应哪个结果,处理结果使用<result&g ...

  4. ubuntu 14.04 64位安装HTK3.5

    1.http://htk.eng.cam.ac.uk/download.shtml 官网下载HTK source code以及HDecode 2.分别解压HTK-3.5.beta-2.tar.gz.H ...

  5. Python 安装虚拟环境

    写在前面: 安装指南是在 Ubuntu 下面操作的.不同的 Linux 版本,安装指令不同.所以,该指南的某些指令对于像 CentOS 等非 Ubuntu 系统不适用. 为什么需要使用虚拟环境? 虚拟 ...

  6. struts2 之 struts2类型转换

    1. 在struts2中,相比servlet来时,获取数据时,程序员没有进行手动的类型转换,类型转换工作都有struts2来完成处理,但愿对于自定义类型数据,struts2不会帮助我们完成类型转换工作 ...

  7. Nginx反向代理以及负载均衡配置

    项目地址:http://git.oschina.net/miki-long/nginx 前提:最近在研究nginx的用法,在windows上小试了一下,由于windows下不支持nginx缓存配置,所 ...

  8. jwt token Example - Python

    0 Pre Install Python3 Install PyCrypto Install PyJWT 1 token 由三部分组成 header, payload, sign 并用逗号连接各部分 ...

  9. 光场相机重聚焦之二——Lytro Illum记录光场

    上一节中大概讲述了光场相机和光场的参数化表示,这一节就说一下光场相机内部是如何记录光场以及实现重聚焦的. 博主用的是Lytro Illum,所以就以Illum为例来说了,Illum的功能还是挺多的,上 ...

  10. ADO.NET 获取SQL SERVER数据库架构信息

    1.确定可用字段数目 sqlDataReader类提供了FieldCount属性,可确定查询反悔了多少个字段. 2.确定返回行的数目 sqlDataReader中没有指示可用行的属性. 3.确定字段的 ...