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. 拦截QWebView弹出窗口

    环境 系统:win7 64位旗舰版 软件:VS2013.QT5.5.1-32位 概述 当网页打开一个新的窗口时,我们有时候需要根据URL地址来判断弹出窗口是否合理,如果合理则弹出新窗口,否则不弹出.本 ...

  2. PHP中 post 与get的区别 详细说明

    1.Get 方法通过 URL 请求来传递用户的数据,将表单内各字段名称与其内容,以成对的字符串连接,置于 action 属性所指程序的 url 后,如[url]http://www.jincaib.c ...

  3. java设计模式(三)

    单例模式在一个jvm中有且仅有一个对象(1)内部静态类实现 class Singleton{ /*构造方法私有 防止实例化*/ private Singleton(){}; public static ...

  4. scala正则表达式

       正则表达式     Scala 通过 scala.util.matching 包种的 Regex 类来支持正则表达式 scala.util.matching.Regex.构造一个Regex对象, ...

  5. openstack私有云布署实践【5 数据库MariaDB 集群】

    kxcontroller1   kxcontroller2  controller1 这3台作角色 确保服务器的域名解析访问正常   确保NTP时间同步   配置HAproxy主备访问,其中的一项数据 ...

  6. HDU 1248 寒冰王座

    完全背包 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  7. Java知识补充

    1.SUN,为standford university network 2.java的标志位咖啡,java本意为南美的一种咖啡.因为oak已被注册 3.JDK为java se development ...

  8. validform 怎么验证小数。

    <input type="text" class="input-text" value="{$info.score}" placeho ...

  9. Web安全知多少

    随着Web2.0.网络社交等一系列新型的互联网产品的诞生,基于Web环境的互联网应用越来越广泛,企业信息化的过程中,越来越多的应用都架设在Web平台上.Web业务的迅速发展吸引了黑客们的强烈关注,接踵 ...

  10. POJ 1230 Pass-Muraille#贪心+vector迭代器用法

    (- ̄▽ ̄)-* (注意下面代码中关于iterator的用法,此代码借鉴某大牛) #include<iostream> #include<cstdio> #include< ...