记录编号 | 456997 | 评测结果 | AAAAAAAAAA | ||
---|---|---|---|---|---|
题目名称 | 求lowbit值之和 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 2.246 s | ||
提交时间 | 2017-10-06 11:30:46 | 内存使用 | 22.29 MiB | ||
#include<bits/stdc++.h> #define MAXN 60010 #define MOD 998244353 using namespace std; int T,ch[MAXN<<5][2],cnt,ans,siz[MAXN<<5],N; void Insert(int x){ int now=1; for(int i=0;i<31;i++){ bool op=(x>>i)&1; if(!ch[now][op])ch[now][op]=++cnt; ans=(ans+1LL*siz[ch[now][op^1]]*(1<<(i+1))%MOD)%MOD; now=ch[now][op]; siz[now]++; } } int x; int main(){ freopen("lowbit.in","r",stdin); freopen("lowbit.out","w",stdout); scanf("%d",&T); for(int cas=1;cas<=T;cas++){ scanf("%d",&N); memset(ch,0,sizeof(ch)); memset(siz,0,sizeof(siz)); ans=0;cnt=1; for(int i=1;i<=N;i++){ scanf("%d",&x); Insert(x); } printf("Case #%d: %d\n",cas,ans); } return 0; }