[BZOJ2728][HNOI2012]与非
出错竟然是1LL写成了 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #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; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步