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. 关于python的元类

    当你创建一个类时: class Foo(Bar): pass Python做了如下的操作: Foo中有__metaclass__这个属性吗?如果是,Python会在内存中通过__metaclass__ ...

  2. poj 1308Bugs Integrated, Inc. [三进制状压]

    题目链接[http://poj.org/problem?id=1038] 题意: 给出一个N*M大小的图,图中有K个坏点.N (1 <= N <= 150), M (1 <= M & ...

  3. python获取

    def anc():pass print anc.__name__ def timeit(func): def run(*argv): print "this function name i ...

  4. IOS开发小技巧,知识点

    1.IOS模拟器第一次打开需要进入“设置”中关掉"Auto-Capitalization"选项. 2.NSInteger转化 NSString类型: [NSString strin ...

  5. hdu_5903_Square Distance(dp)

    题目链接:hdu_5903_Square Distance 题意: 给你一个长度为n的a串,一个数m,现在让你构造一个长度也为n的b串,使这个串是由两个相同的串拼起来的,并且和a串对应的位不同的数量为 ...

  6. Linux中kettle启动spoon.sh遇到的问题

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAccAAAAYCAIAAAAAgaGrAAAE1klEQVR4nO1b2ZWrMAylLgpyPa7Gzb

  7. JSP中的EL语言

    1,EL(Expression Language)是从JavaScript得到启发的一种表达式语言, 2,EL表达式包含文字,操作符,变量,函数调用: 3,EL 存取变量的语法格式:${ userna ...

  8. MC- 交易并设置止损

    using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; using ATCenterP ...

  9. 关于oracle数据库(4)数据类型

    数据类型 字符数据类型char:固定长度字符串,最大可以存放2000字节 字符串varchar2:可变长度字符串,最大可以存放2GB数值类型数据 数字number:可以存放整数.浮点数.实数 numb ...

  10. 哈密顿圈~Lingo程序

    sets: c/1..15/:u; link(c,c):w,x; endsets data: w=@ole('第二题第一组.xls','d'); enddata n=@size(c); min=@su ...