Bitwise And Queries
Bitwise And Queries
Time limit: 1500 ms
Memory limit: 128 MBYou 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≤105
- 1 \leq a \leq b \leq 10^{18}1≤a≤b≤1018
- 0 \leq x \leq 10^{18}0≤x≤1018
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的更多相关文章
- CF-1451 E Bitwise Queries 异或 交互题
E - Bitwise Queries 传送门 题意 有一组序列,长度为 \(n(4\le n \le 2^{16})\),且 \(n\) 为 2 的整数次幂,序列中数值范围为 [0,n-1], 每次 ...
- 【做题记录】CF1451E2 Bitwise Queries (Hard Version)
CF1451E2 Bitwise Queries (Hard Version) 题意: 有 \(n\) 个数( \(n\le 2^{16}\) ,且为 \(2\) 的整数次幂,且每一个数都属于区间 \ ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- 实践 HTML5 的 CSS3 Media Queries
先来介绍下 media,确切的说应该是 CSS media queries(CSS 媒体查询),媒体查询包含了一个媒体类型和至少一个使用如宽度.高度和颜色等媒体属性来限制样式表范围的表达式.CSS3 ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问
delphi ado 跨数据库访问 语句如下 ' and db = '帐套1' 报错内容是:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATE ...
- CSS3 Media Queries 实现响应式设计
在 CSS2 中,你可以为不同的媒介设备(如屏幕.打印机)指定专用的样式表,而现在借助 CSS3 的 Media Queries 特性,可以更为有效的实现这个功能.你可以为媒介类型添加某些条件,检测设 ...
- 使用CSS3 Media Queries实现网页自适应
原文来源:http://webdesignerwall.com 翻译:http://xinyo.org 当今银屏分辨率从 320px (iPhone)到 2560px (大屏显示器)或者更大.人们也不 ...
- SQL Queries from Transactional Plugin Pipeline
Sometimes the LINQ, Query Expressions or Fetch just doesn't give you the ability to quickly query yo ...
随机推荐
- 11.Linux用户管理
本笔记说的Linux用户管理主要包括以下内容: 1.用户配置文件(/etc/passwd /etc/shadow) 2.组配置文件(/etc/group /etc/gshadow) 3.用户缺省配 ...
- JavaScript基础学习(五)—其他引用类型
JavaScript定义了两个内置对象: Global和Math. 一.Global对象 1.URI编码方法 Global对象的encodeURI()和encodeURICompo ...
- 1135: 零起点学算法42——多组测试数据(求和)IV
1135: 零起点学算法42--多组测试数据(求和)IV Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted ...
- 08 Noise and Error
噪声:误标.对同一数据点的标注不一致.数据点信息不准确... 噪声是针对整个输入空间的. 存在噪声的情况下,VC bound依旧有用: 存在噪声,就是f--->p(y|x),f是p的特殊情况:如 ...
- C#7的新语法
阅读目录 out变量 元组(Tuples) 模式匹配(Pattern matching) 本地引用和返回(Ref locals and returns) 本地函数(Local functions) 表 ...
- 如何在 FineUIMvc 中引用第三方 JavaScript 库
声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 引入第三方颜色选择器 在 FineUIMvc 中使用第三方 JavaScript 遵循一定的约定,也非常简单. 下面以官网示例为 ...
- bzoj4817 [Sdoi2017]树点涂色
Description Bob有一棵n个点的有根树,其中1号点是根节点.Bob在每个点上涂了颜色,并且每个点上的颜色不同.定义一条路 径的权值是:这条路径上的点(包括起点和终点)共有多少种不同的颜色. ...
- 使用 PHPStorm + Xdebug 实现断点调试(二)
一.配置 Xdebug 配置 Xdebug 相关参数,在 php.ini 文件中新增如下配置,如果没安装的,请参考<PHP 安装 Xdebug扩展>: [xdebug] xdebug.re ...
- get和post提交数据的区别
get是客户端向服务器索取数据的请求,设定的初衷是,客户端(浏览器)给服务器发送请求,然后服务器再返回给客户端其要求的数据. 那么为什么说get也能提交数据呢? 我们仔细理解第一句话“客户端(浏览器) ...
- CSS清除浮动各种方法
当容器的高度为auto,且容器的内容中有浮动(float为left或right)的元素,在这种情况下,容器的高度不能自动伸长以适应内容的高度,使得内容溢出到容器外面而影响(甚至破坏)布局的现象.这个现 ...