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. Users is not mapped(Hibernate实体类采用注解)

    今天做简单的登陆验证web应用时,用HQL语句查询数据表时 总是出现Users is not mapped [from Users u where u.username=? and u.passwor ...

  2. 郑州尚学堂:如何在Java中创建对象

    作为Java开发者,每天都会创建大量的对象,但是,我们总是使用管理依赖系统(如Spring框架)来创建这些对象.其实还有其他方法可以创建对象,在接下来的文章中我会进行详细介绍. 1.使用new关键字 ...

  3. dropdown-toggle 的点击禁用

    <div class="dropdown select-dropdown" id="choiceTagdiv"> <a class=" ...

  4. this笔记

    在js中,如果this在全局变量和函数中this指window,在在对象中至所挂载的这个对象.

  5. js-学习方法之3

    熟悉JavaScript每一个方法的作用 这一要求听起来似乎有点不太实际,我想这个要求对于像C#.JAVA这些大型语言来说确实是,因为这些语言类库实在太庞大了,相信没有人可以全面记住它,而且也是没有必 ...

  6. 数据库DateTime类型为空的处理

    一,写一个辅助类,将该方法设为静态,先装换为object,在转为DateTime,返回DateTime public class DateTimeHelper { public static Date ...

  7. PHP导出一个txt文本文件

    <?php Header( "Content-type:   application/octet-stream "); Header( "Accept-Ranges ...

  8. socket的accept函数解析

    今天与同学争执一个话题:由于socket的accept函数在有客户端连接的时候产生了新的socket用于服务该客户端,那么,这个新的socket到底有没有占用一个新的端口? 讨论完后,才发现,自己虽然 ...

  9. HttpClient, HttpClientHandler, and WebRequestHandler介绍

    注:本文为个人学习摘录,原文地址:https://blogs.msdn.microsoft.com/henrikn/2012/08/07/httpclient-httpclienthandler-an ...

  10. 2016NEFU集训第n+3场 E - New Reform

    Description Berland has n cities connected by m bidirectional roads. No road connects a city to itse ...