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

  1. /* ***********************************************
  2. Author :kuangbin
  3. Created Time :2013/9/14 星期六 11:59:04
  4. File Name :2013成都网络赛\1010.cpp
  5. ************************************************ */
  6.  
  7. #pragma comment(linker, "/STACK:1024000000,1024000000")
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <iostream>
  11. #include <algorithm>
  12. #include <vector>
  13. #include <queue>
  14. #include <set>
  15. #include <map>
  16. #include <string>
  17. #include <math.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. using namespace std;
  21. const int MAXN = ;
  22. int a[MAXN];
  23. int num[];
  24. int bit[];
  25.  
  26. int main()
  27. {
  28. //freopen("in.txt","r",stdin);
  29. //freopen("out.txt","w",stdout);
  30.  
  31. int T;
  32. int n,m;
  33. bit[] = ;
  34. for(int i = ;i <= ;i++)
  35. bit[i] = *bit[i-];
  36. scanf("%d",&T);
  37. int iCase = ;
  38. while(T--)
  39. {
  40. iCase++;
  41. scanf("%d%d",&n,&m);
  42. for(int i = ;i < n;i++)
  43. scanf("%d",&a[i]);
  44. long long tot = (long long)n*(n+)/;
  45. int last = ;
  46. int i = ,j = ;
  47. memset(num,,sizeof(num));
  48. long long sum = ;
  49. while(j < n)
  50. {
  51. for(int k = ;k <=;k++)
  52. if(a[j] & bit[k])
  53. num[k]++;
  54. int s = ;
  55. for(int k = ;k <= ;k++)
  56. if(num[k])
  57. s += bit[k];
  58. if(s >= m)
  59. {
  60. while(s >=m)
  61. {
  62. for(int k = ;k <= ;k++)
  63. if(a[i] & bit[k])
  64. num[k]--;
  65. s = ;
  66. for(int k = ;k <= ;k++)
  67. if(num[k])
  68. s += bit[k];
  69. i++;
  70. //cout<<i<<endl;
  71. }
  72. sum += (long long)(n-j)*(i-last);
  73. last = i;
  74. }
  75. j++;
  76. }
  77. printf("Case #%d: ",iCase);
  78. //cout<<tot<<" "<<sum<<endl;
  79. cout<<tot-sum<<endl;
  80. }
  81. return ;
  82. }

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. CSS-3 box-shadow 的使用

    box-shadow是给对象实现图层阴影效果的. 语法: E {box-shadow: <length> <length> <length>?<length& ...

  2. 分布式监控工具Ganglia 介绍 与 集群部署.

    如果你目的很明确就是冲着标题来的,不爱看我唠叨,请直接进入第二个分割线之后的内容. 其实之前就是有做Swift监控平台的打算的,但是因为没什么硬性需求么,也不要紧的,就一直搁置了.最近实验室来了个大二 ...

  3. iOS 解决汉字联想输入,导致字数限制失效的问题

    字数限制的问题点在于汉语可以无限汉语联想词汇,导致字数限制对于汉字输入就失去的作用.我们的做法是监听键盘联想出来的汉子,将其统计: 1 在viewDidLoad里面监听文本变化的通知 - (void) ...

  4. SQLSTATE[42000]

    SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT() ...

  5. mysql.user细节三问

    一.如何拒绝用户从某个精确ip访问数据库假如在mysql.user表中存在用户'mydba'@'192.168.85.%',现在想拒绝此用户从某个精确ip访问数据库 # 创建精确ip用户,分配不同的密 ...

  6. linux设备驱动归纳总结(三):3面向对象思想和lseek、container_of、write、read 【转】

    linux设备驱动归纳总结(三):3.设备驱动面向对象思想和lseek的实现 转自:http://blog.chinaunix.net/uid-25014876-id-59418.html 一.结构体 ...

  7. bulk_write&Replace_one

    ns=[]ns.append(ReplaceOne({'ip': ok['ip']}, ok, upsert=True))#更新插入 if len(ns) > 0: res = coll.bul ...

  8. YOLOv2训练自己的数据集(VOC格式)

    下周试试,参考:http://blog.csdn.net/ch_liu23/article/details/53558549 http://blog.csdn.net/sinat_30071459/a ...

  9. .NetCore 中使用AppMetrics向InfluxDB中添加监控数据并通过Grafana图像分析

    考虑到分布式部署监控环境是所有的请求情况,所以这一块一般在网关GateWay里面加比较省事,聚合在一起的,如果放在api服务中,如果只有1个还好,一旦部署Node多是很痛苦的事情 这天需要添加的Nug ...

  10. React 中 context 的使用

    官方文档说明(英) 看了别人写的中文博客,再看了官方英文文档,发现还是官方文档讲的浅显易懂一些,看了之后,半翻译半理解地写了这篇博客,更易于新手理解. 介绍 context 是在 react @ 0. ...