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. jQuery之map()和get() map().get().join意思

    jQuery下有个概念叫“类数组”,比如$( " li " ),当取到一个集合的时候,会有数组的一些属性,但是instancseof Array仍然是false.但是var a=$ ...

  2. phpwind 论坛 转移

    前段时间用phpwind 搭建了一个本地论坛系统,也写过一篇随笔,讲phpwind论坛的迁移,昨天网上又对论坛做了迁移,在本地搭建了系统. 使用的是之前没有成功的方法.这种方法挺方便的,之前每次都是重 ...

  3. Centos之常见目录作用介绍(九)

    我们先切换到系统根目录 / 看看根目录下有哪些目录 [root@localhost ~]# cd / [root@localhost /]# ls bin   dev  home  lib64  mn ...

  4. 常用代码页与BOM

    常用代码页:CP437 IBM437 OEM United StatesCP1252表示West European LatinCP932 日本CP949 韩国CP936表示GBK中文编码CP54936 ...

  5. 保存到properties

    @FXMLprivate void savaconfig(ActionEvent event) { try { Properties prop = new Properties(); FileWrit ...

  6. 使用selenium进行密码破解(绕过账号密码JS加密)

    经常碰到网站,账号密码通过js加密后进行提交.通过burp拦截抓到的账号密码是加密后的,所以无法通过burp instruder进行破解.只能模拟浏览器填写表单并点击登录按钮进行破解.于是想到了自动化 ...

  7. Python里面如何拷贝一个对象?

    import copy lst=[1,2,3,4,[1,2]] # 复制列表lst,命名lst2 lst2=copy.copy(lst) print(f'这是lst3:{lst2}') # 深拷贝 l ...

  8. windows server2003/2008中权限账户

    在windows server 2003与windows server 2008 R2中,查看文件夹权限时,尤其是用cacls命令查看时,经常会见nt authority system这样的用户信息. ...

  9. 关于“Cannot find any provider supporting AES/ECB/PKCS7Padding”问题的解决方案

    出现这个问题的原因是:java自带的是PKCS5Padding填充,不支持PKCS7Padding填充 参考:https://stackoverflow.com/questions/20770072/ ...

  10. 剑指offer 面试8题

    面试8题: 题目:二叉树的下一个节点 题目描述:给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. 解题思路:详见剑 ...