本文主要是介绍ZUFE 问题 P: 感受风的韵律,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
数据量太大了,不能暴力莽过,但是抑或运算每个二进制的值相对独立,对了,别用pow(),掉精度
#include<bits/stdc++.h>using namespace std;const int MAXN = 100000 + 10;
int a[MAXN];long long mm = 1e9 + 7;long long quick(int p)
{long long int ans = 1;long long int q = 2, t = p;while(p){if(p & 1) //二进制下最后一位为1即为真,0即为否ans = ans * q;q=q*q;p>>=1;}return ans;
}
int main()
{int T,n;cin >> T;while(T -- ){cin >> n;long long ans = 0;for(int i = 1; i <= n ; i ++)cin >> a[i];for(int i = 1 ; i <= 31; i ++){long long l = 0 , r = 0;for(int j = 1; j <= n ; j++){if(a[j]&1)l ++;elser ++;a[j] >>= 1;}//cout << l << " " << r << " " <<pow(2,i) << endl;int t = quick(i);long long temp = l * r * t;temp %= mm;ans += temp;ans %= mm;}ans %= mm;cout << ans << endl;}return 0;
}
这篇关于ZUFE 问题 P: 感受风的韵律的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!