[C++][Different Bits Sum Pairwise] O(N)


#1
const int MODVAL = 1e9+7;

int Solution::cntBits(vector<int> &A) {
    long count = 0;
    for(int i=30; i>=0; i--) {
        long bit_i_oneCount = 0, bit_i_zeroCount = 0;
        for(auto it: A)
            bit_i_oneCount += (it>>i) & 0x1;
        bit_i_zeroCount = long(A.size()) - bit_i_oneCount;
        count = (count + (bit_i_zeroCount * bit_i_oneCount) % MODVAL) % MODVAL;
    }
    return (count * 2) % MODVAL;
}