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. java note

    1.List特点:元素有放入顺序,元素可重复 ,Set特点:元素无放入顺序,元素不可重复.

  2. 二十三、oracle pl/sql分类三 包

    包用于在逻辑上组合过程和函数,它由包规范和包体两部分组成.1).我们可以使用create package命令来创建包,如:i.创建一个包sp_packageii.声明该包有一个过程update_sal ...

  3. C/C++ 语言中的表达式求值(原文作者:裘宗燕)

    经常可以在一些讨论组里看到下面的提问:“谁知道下面C语句给n赋什么值?”m = 1; n = m+++m++;最近有位不相识的朋友发email给我,问为什么在某个C++系统里,下面表达式打印出两个4, ...

  4. Ubuntu下Android apk反编译

    需要用到的工具 1.apktool_2.0.3.jar https://bbuseruploads.s3.amazonaws.com/0becf6a1-1706-4f2e-9ae6-891e00a8d ...

  5. 部分服务器使用phpExcel会报错

    其中一个错误提示是:Fatal error: 'break' not in the 'loop' or 'switch' context in /var/www/htdocs/hanya/ThinkP ...

  6. openstack私有云布署实践【4.2 上层代理haproxy+nginx配置 (办公网测试环境)】

    续上一节说明 一开始我也是使用haproxy来做的,但后来方式改了,是因为物理机controller的高配置有些浪费,我需要1组高可用的上层nginx代理服务器来实现其它域名80代理访问,很多办公网测 ...

  7. 《Android系统源代码情景分析》连载回忆录:灵感之源

    上个月,在花了一年半时间之后,写了55篇文章,分析完成了Chromium在Android上的实现,以及Android基于Chromium实现的WebView.学到了很多东西,不过也挺累的,平均不到两个 ...

  8. 计算机网络课程优秀备考PPT之第四章介质访问控制层(四)

    为了记录自己从2016.9~2017.1的<计算机网络>助教生涯,也为了及时梳理和整写笔记! 前期博客是, 计算机网络课程优秀备考PPT之第一章概述(一) 计算机网络课程优秀备考PPT之第 ...

  9. git 第一次 push 遇到问题

    开始用 git 的时候我只会 git clone git pull git push 这三个命令满足了我的基本需求,到自己创建仓库的时候遇到了问题, git remote add origin htt ...

  10. jQuery动态添加元素事件

    在项目中遇到需要jQuery动态添加元素的事件,做了一个demo,方便以后遇到相同的问题可以用上: <!DOCTYPE html> <html> <head> &l ...