A Bit Fun

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 423    Accepted Submission(s): 270

Problem Description
There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . 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 <= 230) Then n numbers come in the second line which is the array a, where 1 <= ai <= 230.
 
Output
For every case, you should output "Case #t: " at first, without quotes. The t 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
 
Recommend
liuyiding
 

用位数num维护l,r两个指针。

扫描一遍。

复杂度31*n

 /* ***********************************************
Author :kuangbin
Created Time :2013/9/14 星期六 11:59:04
File Name :2013成都网络赛\1010.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = ;
int a[MAXN];
int num[];
int bit[]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T;
int n,m;
bit[] = ;
for(int i = ;i <= ;i++)
bit[i] = *bit[i-];
scanf("%d",&T);
int iCase = ;
while(T--)
{
iCase++;
scanf("%d%d",&n,&m);
for(int i = ;i < n;i++)
scanf("%d",&a[i]);
long long tot = (long long)n*(n+)/;
int last = ;
int i = ,j = ;
memset(num,,sizeof(num));
long long sum = ;
while(j < n)
{
for(int k = ;k <=;k++)
if(a[j] & bit[k])
num[k]++;
int s = ;
for(int k = ;k <= ;k++)
if(num[k])
s += bit[k];
if(s >= m)
{
while(s >=m)
{
for(int k = ;k <= ;k++)
if(a[i] & bit[k])
num[k]--;
s = ;
for(int k = ;k <= ;k++)
if(num[k])
s += bit[k];
i++;
//cout<<i<<endl;
}
sum += (long long)(n-j)*(i-last);
last = i;
}
j++;
}
printf("Case #%d: ",iCase);
//cout<<tot<<" "<<sum<<endl;
cout<<tot-sum<<endl;
}
return ;
}

HDU 4737 A Bit Fun (2013成都网络赛)的更多相关文章

  1. HDU 4737 A Bit Fun 2013成都 网络赛 1010

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4737 题目大意:给定一系列数,F(i,j)表示对从ai到aj连续求或运算,(i<=j)求F(i, ...

  2. HDU 4734 F(x) (2013成都网络赛,数位DP)

    F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)

    Minimum palindrome Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. HDU 4733 G(x) (2013成都网络赛,递推)

    G(x) Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. HDU 4730 We Love MOE Girls (2013成都网络赛,签到水题)

    We Love MOE Girls Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 4763 Theme Section (2013长春网络赛1005,KMP)

    Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  7. HDU 4759 Poker Shuffle(2013长春网络赛1001题)

    Poker Shuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  9. HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

随机推荐

  1. svn 更新代码

    SVN 更新代码 --force # 强制覆盖 /usr/bin/svn --username user --password passwd co $Code ${SvnPath}src/ # 检出整 ...

  2. 200行代码实现RPC框架

    之前因为项目需要,基于zookeeper和thrift协议实现了一个简单易用的RPC框架,核心代码不超过200行. zookeeper主要作用是服务发现,thrift协议作为通信传输协议, 基于com ...

  3. HDU 1431 素数回文 离线打表

    题目描述:给定一个区间,将这个区间里所有既是素数又是回文数的数输出来. 题目分析:这题的这个数据范围比较大,达到了10^8级别,而且输入的数据有多组,又因为判断一个数是否是回文数貌似只有暴力判断,时间 ...

  4. python中的__call__

    如果python中的一个类定义了 __call__ 方法,那么这个类它的实例就可以作为函数调用,也就是实现了 () 运算符,即可调用对象协议 下面是一个简单的例子: class TmpTest: de ...

  5. F - Friends ZOJ - 3710(暴力)

    题目链接:https://cn.vjudge.net/contest/280949#problem/F 题目大意:给你n个人,然后给你m个关系,每个关系输入t1, t2 .代表t1和t2是朋友关系(双 ...

  6. ASP.NET程序发布

    详细流程请参考文章:https://www.cnblogs.com/wangjiming/p/6286045.html 主要补充个人操作过程中遇到的问题: 1)网站发布完成后,站点下没有aspnet_ ...

  7. 使用 Application Loader提交IPA文件到苹果市场

    打包.导出ipa包后剩下的就是要将ipa包推到appstore.Application Loader是苹果提供的ipa包提交工具. 1.启动Application Loader 打开xcode,在xc ...

  8. nginx开启gzip压缩前端css,js

    利用nginx实现前后端分离, nginx配置文件,nginx.conf配置采用gzip压缩: 在server中添加: gzip on; #开启gzip gzip_min_length 1k; #低于 ...

  9. wpf image 指定Stretch="None" 不拉伸的时候,仍然拉伸的解决办法

    I think TI82 is right on this issue. The image become bigger than you expect because its dpi doesn't ...

  10. leetcode 题集

    775. Global and Local Inversions 统计相邻元素组成的逆序对(local inversion)和全局逆序对的数量(global inversion) 思路:local i ...