Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 538 Accepted Submission (s): 259
Problem Descriptionmemphis loves XOR very musch. Now he gets A array a.the length of A are n.now he wants to know the sum of all (Lowbit (Ai XorAJ ))(i,j∈[1,n])
We define that lowbit (x) =2k , k is the smallest integer satisfied (x and 2k ) >0
specially,lowbit (0) =0
Because The ans may be too big. Just need to Output < Span id= "mathjax-span-39" class= "math" > an s mod 998244353
Inputmultiple test Cases, the first line contains a integer T (no more than), indicating the number of cases. Each test case contains the lines
The first line have an integerN
The second line hasNIntegersA1 ,A2 ....AN
n∈[1,5∗4] ,Ai∈[0,2]
Outputfor, the output should occupies exactly one line. The output format is case #x: ans, where x is the data number begins at 1.
Sample Input254 0 2 7 052 6 5 4 0
Sample outputcase #1:36Case #2:40
/*time 62msby atrp*/#include <cstdio> #include <algorithm> #include <cstring> #include <map> Using namespace Std;typedef long long ll;const int N = 50005;int a[n];int N, FORC;LL ans;int cmp (int a, int b) {return (A & (1 << forc)) < (b & (1 << forc));} int calc (int low, int. high)//Look for sort after A[low: High-1] The Forc of the second binary in a different demarcation point, the interval is [Low,high]; {int i; for (i = low, I < high, ++i) if ((A[i] & (1 << forc) ^ (a[i + 1] & (1 << forc)) break; if (i = = high) return i; else return i + 1;//Note here that the boundary handles}void solve (int low, int.) {sort (A + low, A + high, CMP); int m = Calc (low, high); printf ("[%d]-[%d]\n", M, high); int mi = *min_element (A + low, A + high); int mx = *max_element (A + low, A + high); if (mi = = mx) return;//when the elements in [Low,high] are equal, there is no need to continue the recursive forc++; Solve (low, m); Solve (M, high); forc--; Ans + = ((m-low)% 998244353) * ((high-m)% 998244353) * (1 << forc);} int MaiN () {int T, CA = 1; scanf ("%d", &t); while (T--) {scanf ("%d", &n); for (int i = 0; i < n; ++i) scanf ("%d", &a[i]); FORC = 0; Ans = 0; Solve (0, N); printf ("Case #%d:%lld\n", ca++, (ans << 1)% 998244353); }}
Sourcebestcoder Round #44
Hdu 5269 ZYB loves Xor I