A Bit Fun

Time Limit : 5000/2500ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 43   Accepted Submission(s) : 13
Problem Description
There are n numbers in a array, as a[sub]0[/sub], a[sub]1[/sub] ... , a[sub]n-1[/sub], and another number m. We define a function f(i, j) = a[sub]i[/sub]|a[sub]i+1[/sub]|a[sub]i+2[/sub]| ... | a[sub]j[/sub] . 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 <= 2[sup]30[/sup]) Then n numbers come in the second line which is the array a, where 1 <= a[sub]i[/sub] <= 2[sup]30[/sup].
 
Output
For every case, you should output "Case #t: " at first, without quotes. The [I]t[/I] 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 <stdio.h>
#include <stdlib.h>
#include <string.h> int main()
{
int T,A,B,sign;
long a[],m,n,sum,tmp,t,i,j;
scanf("%d",&T);
t=;
while(T--)
{
sign=;
scanf("%ld%ld",&n,&m);
for(i=;i<n;i++)
scanf("%ld",&a[i]);
for(i=;i<n;i++)
{
tmp=a[i];
for(j=i;j<n;j++)
{
tmp=tmp|a[j];
if(tmp<m)
sign++;
else
break;
}
}
printf("Case #%d: %d\n",t,sign);
t++;
}
return ;
}

随机推荐

  1. Linux文件挂载命令mount

    在linux系统中硬盘.u盘.光驱等其他设备都需要挂载后才能正常使用.下面是对挂载命令mount使用方法的一些总结. 文件挂载命令mountmount [-t 文件系统类型][-L卷标名][-o特殊选 ...

  2. php灌水

    <?php $data=array('name'=>'paul','mail'=>'paulversion@163.com') $data=http_build_query($dat ...

  3. App提交Appstore审核流程【转】

    这是一个app提交到iTunces Connect被拒了4次摸索出来的经验,说多了都是泪,先让我擦擦...好了,话不多说,为了让中国的app不再那么容易被拒,或者被拒了不知道该咋办,我把我的小经验在这 ...

  4. [妙味JS基础]第十一课:字符串、查找高亮显示

    知识点总结 字符串方法 var str = '2014年新春快乐哈' * length 字符串长度 str.length =>10 ------------------------------- ...

  5. 认识<meta>

    概要:在查看网页源码的时候,经常发现有<meta>标签存在,于是查了一下它的作用,发现有很多功能.下面就简单的阐述一些常见的功能. 一[什么是<meta>标签] meta,即m ...

  6. linux文件系统拓展属性

    在研究GlusterFS中,发现GlusterFS使用了文件系统的Extended Attributes,中文可以称之为文件系统扩展属性.由于资料比较少,中文资料更少,因此把记录几点Extended ...

  7. IOS CrackMe 破解学习

    一直在看别人如何破解一个app,下面自己也尝试着学习怎么去破解一个app的密码,下面是完整的过程. 准备工作: 一台mac或者pc安装了ssh客户端 一台越狱的iphone iphone上安装了ope ...

  8. 有关下行HARQ的一切

    1. 对于下行HARQ,有几种类型的下行传输需要UE反馈ACK/NACK 动态调度的下行传输:UE收到一个使用C-RNTI或TC-RNTI(对应随机接入过程中的Msg4)加扰的PDCCH和PDSCH, ...

  9. Excel教程(12) - 数学和三角函数

    ABS     用途:返回某一参数的绝对值.   语法:ABS(number) 参数:number 是需要计算其绝对值的一个实数. 实例:如果 A1=-16,则公式"=ABS(A1)&quo ...

  10. static 控件颜色修改

    在对话框上放一个StaticText控件后如果文字长度不能铺满控件的 rect,如下: 那么运行时会出现如下效果 通过MSG_WM_CTLCOLORSTATIC消息修改static控件背景色模式为透明 ...