2013 ACM/ICPC Asia Regional Chengdu Online_A Bit Fun
2013-09-17 20:35
399 查看
ABitFun
TimeLimit:5000/2500MS(Java/Others)MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):2072AcceptedSubmission(s):729
[align=left]ProblemDescription[/align]
Therearennumbersinaarray,asa0,a1...,an-1,andanothernumberm.Wedefineafunction
f(i,j)=ai|ai+1|ai+2|...|aj.Where"|"isthebit-ORoperation.
(i<=j)
Theproblemisreallysimple:pleasecountthenumberofdifferentpairsof(i,j)wheref(i,j)<m.
[align=left]Input[/align]
ThefirstlinehasanumberT(T<=50),indicatingthenumberoftestcases.
Foreachtestcase,firstlinecontainstwonumbersnandm.(1<=n<=100000,1<=m<=230)Thennnumberscomeinthesecondlinewhichisthearraya,where1<=ai
<=230.
[align=left]Output[/align]
Foreverycase,youshouldoutput"Case#t:"atfirst,withoutquotes.The
tisthecasenumberstartingfrom1.
Thenfollowstheanswer.
[align=left]SampleInput[/align]
2
36
135
24
54
[align=left]SampleOutput[/align]
Case#1:4
Case#2:0
#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#defineN100001
usingnamespacestd;
intnum
,bit[32];
intmain(){
//freopen("in.txt","r",stdin);
intn,m,t,casen=1;
cin>>t;
while(t--){
cin>>n>>m;
memset(bit,0,sizeof(bit));
inti,j,k;
longlongcnt=0;
for(i=1;i<=n;i++)
scanf("%d",&num[i]);
intsum=0;
j=1;
for(i=1;i<=n;i++){
if(j<i)j=i;
for(;j<=n&&(sum|num[j])<m;){
for(k=0;k<31;k++){
if(num[j]&(1<<k))
bit[k]++;
}
sum|=num[j];
j++;
}
cnt+=(longlong)(j-i);
if(j>i)
for(k=0;k<31;k++){
if(num[i]&(1<<k)){
bit[k]--;
if(!bit[k])
sum^=(1<<k);
}
}
//cout<<cnt<<endl;
}
printf("Case#%d:",casen++);
printf("%I64d\n",cnt);
}
return0;
}
相关文章推荐
- hdu 4737 A Bit Fun 数列(2013 ACM/ICPC Asia Regional Chengdu Online 1010)
- hdu 4737 A Bit Fun || 2013 ACM/ICPC Asia Regional Chengdu Online || 简单题
- HDU 4731 Minimum palindrome 找规律 (2013 ACM/ICPC Asia Regional Chengdu Online 1004)
- hdu 4734 F(x)2013 ACM/ICPC Asia Regional Chengdu Online
- hdu 4731 Minimum palindrome 找规律 (2013 ACM/ICPC Asia Regional Chengdu Online 1004)
- hdu 4734 F(x) 数位dp (2013 ACM/ICPC Asia Regional Chengdu Online 1007)
- 2013 ACM/ICPC Asia Regional Chengdu Online
- 2013 ACM/ICPC Asia Regional Chengdu Online 个人总结
- HDU4734——2013 ACM/ICPC Asia Regional Chengdu Online
- 2013 ACM/ICPC Asia Regional Chengdu Online
- HDU 4729 An Easy Problem for Elfness(主席树)(2013 ACM/ICPC Asia Regional Chengdu Online)
- hdu 4731 Minimum palindrome 找规律 (2013 ACM/ICPC Asia Regional Chengdu Online 1004)
- 2013 ACM/ICPC Asia Regional Chengdu Online---1003
- 2013 ACM/ICPC Asia Regional Chengdu Online
- 2013 ACM/ICPC Asia Regional Chengdu Online
- 2013 ACM/ICPC Asia Regional Chengdu Online HDU 4731 Minimum palindrome(规律)
- 2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome
- HDU 4735 Little Wish~ lyrical step~(DLX搜索)(2013 ACM/ICPC Asia Regional Chengdu Online)
- 2013 ACM/ICPC Asia Regional Chengdu Online
- HDU 4737 A Bit Fun(2013 ACM/ICPC Asia Regional Chengdu Online)