1466E - Apollo versus Pan

1466E - Apollo versus Pan

A bit of math, (

reference

By the way, the synchronization of cincout is really too bad, btw cf is also stuck in cincout
Insert picture description here

Ideas:
Insert picture description here

code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 5e5 + 10, M = 70;
const ll mod = 1e9 + 7;

ll a[N], have[M], pow2[M];

inline void init1() {
    
    
	pow2[0] = 1;
	for(int i = 1; i <= 65; ++ i) {
    
    
		pow2[i] = pow2[i - 1] * 2 % mod;
	}
}

inline void init() {
    
    
	memset(have, 0, sizeof have);
}

int main() {
    
    
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt","r",stdin);
#endif

	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 

	init1();
	
	int T;
	cin >> T;
	while(T--) {
    
    
		init();
		ll n;
		cin >> n;
		for(int i = 1; i <= n; ++ i) {
    
    
			cin >> a[i];
			for(int j = 0; j <= 60; ++ j) {
    
    
				int u = a[i] >> j & 1;
				if(u) ++ have[j];
			}
		}
		
		ll ans = 0;
		for(int i = 1; i <= n; ++ i) {
    
    
			ll ansOfAnd = 0;
			ll ansOfOr = 0;
			for(int j = 0; j <= 60; ++ j) {
    
    
				if(a[i] >> j & 1) {
    
    
					ansOfAnd = (ansOfAnd + pow2[j] * have[j]) % mod;
					ansOfOr = (ansOfOr + pow2[j] * n) % mod;
				}
				else {
    
    
					ansOfOr = (ansOfOr + pow2[j] * have[j]) % mod;
				}
			}
			ans = (ans + ansOfAnd * ansOfOr % mod) % mod;
		}
		
		cout << ans << endl;
	}
} 

Guess you like

Origin blog.csdn.net/qq_39602052/article/details/113917394