【題解】Codeforces 1466E. Apollo versus Pan

【題目敘述】http://codeforces.com/contest/1466/problem/E

#include <bits/stdc++.h>
using namespace std;
 
long long t, n, a[500005], p = 1e9+7;
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> t;
    while (t--){
        int cnt[65] = {};
        cin >> n;
        for (int i = 0; i < n; i++){
            cin >> a[i];
            for (int j = 0; j < 60; j++){
                if ((a[i]>>j) & 1) cnt[j]++;
            }
        }
        long long ans = 0;
        for (int j = 0; j < n; j++){
            long long toti = 0, totk = 0;
            for (int i = 0; i < 60; i++){
                if ((a[j]>>i) & 1){
                    toti += ((1LL << i)%p)*n;
                    toti %= p;
                    totk += ((1LL << i)%p)*cnt[i];
                    totk %= p;
                }
                else{
                    toti += ((1LL << i)%p)*cnt[i];
                    toti %= p;
                }
            }
            ans += ((toti%p)*(totk%p))%p;
            ans %= p;
        }
        cout << ans << "\n";
    }
}
分享本文 Share with friends