ZYB loves Xor I
Accepts: 142 Submissions: 696 Time Limit: 2000/1000 MS ( Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述ZYB喜欢研究Xor,现在他得到了一个长度为输入描述n 的数组A。于是他想知道:对于所有数对(i,j)(i∈[1,n],j∈[1,n]) ,lowbit(AixorAj) 之和为多少.由于答案可能过大,你需要输出答案对998244353取模后的值 定义lowbit(x)=2k ,其中k是最小的满足(x and 2k)>0 的数 特别地:lowbit(0)=0
一共输出描述T (T≤10 )组数据,对于每组数据: 第一行一个正整数n ,表示数组长度 第二行n 个非负整数,第i 个整数为Ai n∈[1,5?104] ,Ai∈[0,229]
每组数据输出一行Case #x: ans。x表示组数编号,从1开始。ans为所求值。输入样例
2 5 4 0 2 7 0 5 2 6 5 4 0输出样例
Case #1: 36
Case #2: 40
?
#include#include #include #include using namespace std; const long long MOD = 998244353; const int maxn = 30; const int M = 2; long long ans; struct Node { int v; Node *next[M]; }; struct Tree { Node *root; int v; Tree()//constructor { root = new Node; root->v = 0; for(int i=0; i next[i] = NULL; } void insert(int t) { Node *p = root, *q; for(int i=0; i next[tmp] == NULL) { q = new Node; q->v = 1; for(int i=0; i next[i] = NULL; p->next[tmp] = q; p = q; } else { p = p->next[tmp]; p->v++; } } } void find(int t) { Node *p = root; for(int i=0; i next[tmp^1] != NULL) ans = (ans + (p->next[tmp^1]->v)*(long long)(1< next[tmp]; } } }; const int N = 50005; int a[N]; int kase = 0; int main() { int T, n; scanf(%d, &T); while(T--) { ans = 0; Tree tree; scanf(%d, &n); for(int i=0; i ?
?