A Bit Fun

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . Where "|" is the bit-OR operation. (i <= j)
The problem is really simple: please count the number of different pairs of (i, j) where f(i, j) < m.
 
Input
The first line has a number T (T <= 50) , indicating the number of test cases.
For each test case, first line contains two numbers n and m.(1 <= n <= 100000, 1 <= m <= 230) Then n numbers come in the second line which is the array a, where 1 <= ai <= 230.
 
Output
For every case, you should output "Case #t: " at first, without quotes. The t is the case number starting from 1.
Then follows the answer.
 
Sample Input
2
3 6
1 3 5
2 4
5 4
 
Sample Output
Case #1: 4
Case #2: 0
 
Source

2013 ACM/ICPC Asia Regional Chengdu Online

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=1e5+,M=1e6+,inf=1e9+,mod=;
int a[N];
int flag[];
void init()
{
memset(flag,,sizeof(flag));
}
void update(int x,int hh)
{
int sum=;
while(x)
{
flag[sum++]+=x%*hh;
x>>=;
}
}
int getnum()
{
int ans=;
for(int i=;i<=;i++)
{
if(flag[i])
ans+=<<i;
}
return ans;
}
int main()
{
int x,y,z,i,t;
int T,cas=;
scanf("%d",&T);
while(T--)
{
init();
scanf("%d%d",&x,&y);
for(i=;i<=x;i++)
scanf("%d",&a[i]);
int st=;
int en=;
int cnt=;
ll ans=;
int qu=;
while()
{
while(getnum()<y&&en<=x)
update(a[en++],);
if(getnum()<y)
{
ans+=(ll)(en-st)*(en-st+)/;
break;
}
ans+=max(,en-st-);
update(a[st++],-);
}
printf("Case #%d: %I64d\n",cas++,ans);
}
return ;
}

hdu 4737 A Bit Fun 尺取法的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)

    题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...

  2. HDU 5358 First One 数学+尺取法

    多校的题,摆明了数学题,但是没想出来,蠢爆了,之前算了半天的s[i][j]的和,其实是积.其实比赛的时候我连log(s[i][j])+1是s[i][j]的位数都没看出来,说出来都丢人. 知道了这个之后 ...

  3. hdu 6205 card card card 尺取法

    card card card Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. hdu 5510 Bazinga KMP+尺取法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:至多50组数据,每组数据至多500个字符串,每个字符串的长度最长为2000.问最大的下标( ...

  5. HDU 6103 Kirinriki(尺取法)

    http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选 ...

  6. HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))

    小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. HDU 5672 String【尺取法】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5672 题意: 有一个10≤长度≤1,000,000的字符串,仅由小写字母构成.求有多少个子串,包含有 ...

  8. HDU 5358 尺取法+枚举

    题意:给一个数列,按如下公式求和. 分析:场上做的时候,傻傻以为是线段树,也没想出题者为啥出log2,就是S(i,j) 的二进制表示的位数.只能说我做题依旧太死板,让求和就按规矩求和,多考虑一下就能发 ...

  9. HDU 4123 (2011 Asia FZU contest)(树形DP + 维护最长子序列)(bfs + 尺取法)

    题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP ...

随机推荐

  1. COGS 693. [SDOI2005]Antiprime数 唯一分解定理逆用

    693. Antiprime数 ★★   输入文件:antip.in   输出文件:antip.out   简单对比 时间限制:1 s   内存限制:128 MB 如果一个自然数n(n>=1), ...

  2. 160824、ionic添加地图站点

    1.基本的地图显示 <!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset= ...

  3. ZOJ 2059 The Twin Towers(双塔DP)

    The Twin Towers Time Limit: 2 Seconds      Memory Limit: 65536 KB Twin towers we see you standing ta ...

  4. java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x87<b

    实际开发中遇到的 情景: 解决方案:  复制的别人的博客,没测试, Incorrect string value: '\xF0\x9F...' for column 'XXX' at row 1 这个 ...

  5. SSL逐渐演变到TLS

    w https://zh.wikipedia.org/wiki/超文本传输安全协议

  6. 安装git和配置

     首先更新系统 yum  -y update  安装依赖的包 yum -y install curl-devel expat-devel gettext-devel openssl-devel zli ...

  7. echarts系列之动态加载数据

    1.echarts学习前言 最近接触到echarts,发现数据可视化真的是魅力无穷啊,各种变幻的曲线交错,以及‘曼妙’的动画效果真是让人如痴如醉! 下面就来一起欣赏她的美... “ ECharts是中 ...

  8. 常用的JS代码块收集

    /**数组去重一*/ (function (arr) { arr = arr.sort(); for (var i = 0; arr[i]; i++) { if (arr[i] === arr[i + ...

  9. 使用 adb logcat 显示 Android 日志

    本文为转载.  地址:http://www.hanshuliang.com/?post=32 eclipse 自带的 LogCat 工具太垃圾了, 开始用 adb logcat 在终端查看日志; 1. ...

  10. Java关键字this

    Java关键字this只能用于方法方法体内.当一个对象创建后,Java虚拟机(JVM)就会给这个对象分配一个引用自身的指针,这个指针的名字就是 this.因此,this只能在类中的非静态方法中使用,静 ...