赞
踩
把所有数按位去做,通过位运算得出每位上
1
1
1的个数
然后再疯狂暴力判断是否符合条件,是就累加答案
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> #include<set> #include<queue> #include<vector> #include<map> #include<list> #include<ctime> #include<iomanip> #include<string> #include<bitset> #include<deque> #include<set> #define LL long long #define ch cheap using namespace std; inline LL read() { LL d=0,f=1;char s=getchar(); while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();} return d*f; } LL a[100005],ans,v[35]; int main() { freopen("evolve.in","r",stdin); freopen("evolve.out","w",stdout); LL n=read(),m=read(); for(LL i=1;i<=n;i++) a[i]=read(); LL last=1; for(LL i=1;i<=n;i++) { LL z=0; for(LL j=0;j<=30;j++) v[j]+=(a[i]>>j)&1,z+=(v[j]!=0)<<j; while(z>=m&&last<i) { z=0; for(LL j=0;j<=30;j++) v[j]-=(a[last]>>j)&1,z+=(v[j]!=0)<<j; last++; } ans+=i-last; } cout<<ans; return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。