1 条题解
-
1
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> nums(n); long long total_sum = 0; vector<int> count(31, 0); // 各位上1的计数 for (int i = 0; i < n; ++i) { cin >> nums[i]; total_sum += nums[i]; for (int k = 0; k < 31; ++k) { if (nums[i] & (1 << k)) { count[k]++; } } } long long sum_and = 0; for (int k = 0; k < 31; ++k) { long long cnt = count[k]; sum_and += (cnt * (cnt - 1) / 2) * (1LL << k); } long long total_harmony = 2 * (n - 1) * total_sum - 2 * sum_and; cout << total_harmony << endl; return 0; }
信息
- ID
- 1221
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 8
- 标签
- 递交数
- 19
- 已通过
- 6
- 上传者