[BZOJ2728][HNOI2012]与非
出错竟然是1LL写成了 1
#include<iostream> #include<cstdio> #include<vector> #include<algorithm> using namespace std; typedef long long LL; int n,k,m; LL L,R; vector<LL> a, s1; void sol(){ cin>>n>>k>>L>>R; for(int i=0;i<n;i++){ a.push_back(0); cin>>a[i]; } for(int i=0;i<k;i++){ LL x=(1LL<<k)-1; for(int j=0;j<n;j++) if(a[j]&(1LL<<i)) x&=a[j]; else x&=~a[j]; s1.push_back(x); } sort(s1.begin(),s1.end()); for(int i=1;i<s1.size();i++) if(s1[i]>s1[m]) s1[++m]=s1[i]; } LL ans(LL x){ LL y=0,rc=0; for(int i=m;i>=0;i--){ if((y|s1[i])<=x) { y|=s1[i]; rc+=(1LL<<i); } } if(y<=x) rc++; return rc; } int main(){ ios_base::sync_with_stdio(0); sol(); cout<<ans(R)-ans(L-1)<<endl; return 0; }