Hdu 4737 A Bit Fun Ruler

Source: Internet
Author: User

A Bit Fun

Time limit:5000/2500 MS (java/others) Memory limit:32768/32768 K (java/others)


Problem descriptionthere is 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 the different pairs of (I, J) where F (i, J) < M.

Inputthe first line has a number T (T <=), indicating the number of test cases.
For each test case, first line contains, numbers n and M. (1 <= n <= 100000, 1 <= m <=) then n numbers c Ome in the second line which is the array a, where 1 <= ai <= 230.

Outputfor every case, you should output ' case #t: ' At first, without quotes. The TIs the case number starting from 1.
Then follows the answer.

Sample Input23 61 3 52 45 4

Sample outputcase #1:4Case #2:0

Source

ACM/ICPC Asia Regional Chengdu Online

#include <bits/stdc++.h>using namespacestd;#definell __int64#defineESP 0.00000000001Const intn=1e5+Ten, m=1e6+Ten, inf=1e9+Ten, mod=1000000007;intA[n];intflag[ +];voidinit () {memset (flag,0,sizeof(flag));}voidUpdateintXinthh) {    intsum=0;  while(x) {flag[sum++]+=x%2*hh; X>>=1; }}intGetnum () {intans=0;  for(intI=0; i<= *; i++)    {        if(Flag[i]) ans+=1<<i; }    returnans;}intMain () {intx,y,z,i,t; intt,cas=1; scanf ("%d",&T);  while(t--) {init (); scanf ("%d%d",&x,&y);  for(i=1; i<=x;i++) scanf ("%d",&A[i]); intst=1; inten=1; intCnt=1; ll ans=0; intqu=0;  while(1)        {             while(Getnum () <y&&en<=x) Update (A[en++],1); if(Getnum () <y) {ans+ = (ll) (en-st) * (en-st+1)/2;  Break; } ans+=max (0, en-st-1); Update (A[st++],-1); } printf ("Case #%d:%i64d\n", cas++, ans); }    return 0;}

Hdu 4737 A Bit Fun Ruler

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.