HDU-4737 A Bit Fun 维护
2013-09-28 00:12
351 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4737
题意:给一个数列a0, a1 ... , an-1,令 f(i, j) = ai|ai+1|ai+2| ... | aj,求数列中有多少对f(i,j)满足f(i,j)<m。
转化为二进制数,依次枚举j,那么只要找到第一个满足的 i 就可以了,我们用个数组w[k]标记每位二进制中的1在j左边第一次出现的位置,然后依次根据w[k]数组中的位置从大到小加数,直到大于m为止,就是此时j对应的最小的i。复杂度O(32*n)。
题意:给一个数列a0, a1 ... , an-1,令 f(i, j) = ai|ai+1|ai+2| ... | aj,求数列中有多少对f(i,j)满足f(i,j)<m。
转化为二进制数,依次枚举j,那么只要找到第一个满足的 i 就可以了,我们用个数组w[k]标记每位二进制中的1在j左边第一次出现的位置,然后依次根据w[k]数组中的位置从大到小加数,直到大于m为止,就是此时j对应的最小的i。复杂度O(32*n)。
//STATUS:C++_AC_1312MS_848KB #include <functional> #include <algorithm> #include <iostream> //#include <ext/rope> #include <fstream> #include <sstream> #include <iomanip> #include <numeric> #include <cstring> #include <cassert> #include <cstdio> #include <string> #include <vector> #include <bitset> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> using namespace std; //#pragma comment(linker,"/STACK:102400000,102400000") //using namespace __gnu_cxx; //define #define pii pair<int,int> #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define PI acos(-1.0) //typedef typedef __int64 LL; typedef unsigned __int64 ULL; //const const int N=40; const int INF=0x3f3f3f3f; const int MOD=1000000007,STA=8000010; const LL LNF=1LL<<60; const double EPS=1e-6; const double OO=1e60; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; //Daily Use ... inline int sign(double x){return (x>EPS)-(x<-EPS);} template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} template<class T> inline T lcm(T a,T b,T d){return a/d*b;} template<class T> inline T Min(T a,T b){return a<b?a:b;} template<class T> inline T Max(T a,T b){return a>b?a:b;} template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} //End #define get(a,i) ((a)&(1<<(i))) struct Node{ int l,j; bool operator < (const Node& a)const{ return l>a.l; } }low ; int l ; int T,n,m; int main(){ // freopen("in.txt","r",stdin); int i,j,b,d,num ,ok,w,t,ca=1; LL ans; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); mem(l,0); ans=0; for(i=1;i<=n;i++){ scanf("%d",&b); for(j=0;j<=30;j++){ if(get(b,j))l[j]=i; low[j].l=l[j]; low[j].j=j; } if(b>=m)continue; sort(low,low+31); int sum=0; for(j=0;j<=30;j++){ sum|=low[j].l?1<<low[j].j:0; if(sum>=m)break; } ans+=j<=30?i-low[j].l:i; } printf("Case #%d: %I64d\n",ca++,ans); } return 0; }
相关文章推荐
- hdu 4737 A Bit Fun
- Hdu 4737 A Bit Fun
- HDU-4737-A Bit Fun
- HDU 4737 A Bit Fun 水暴力
- hdu 4737 A Bit Fun 尺取法
- 2013成都网赛1010 hdu 4737 A Bit Fun
- hdu 4737 A Bit Fun
- HDU 4737 A Bit Fun
- HDU 4737 A Bit Fun
- hdu 4737 A Bit Fun 暴力
- HDU 4737 A Bit Fun
- HDU-4737-A Bit Fun-TwoPointer
- 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 4737 A Bit Fun
- hdu 4737 A Bit Fun
- hdu 4737 A Bit Fun 2013成都赛区网络赛最后一题
- hdu 4737 A Bit Fun
- HDU 4737 A Bit Fun 2013成都 网络赛 1010
- HDU 4737 A Bit Fun 解题报告