1 条题解

  • 0
    @ 2025-11-5 15:12:30
    • 按二进制位,分别计算每一位的贡献
    • 时间复杂度:O(nlog(n))O(nlog(n))
    #include <bits/stdc++.h>
    using namespace std;
    
    using i64 = long long;
    const int P = 998244353;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
    
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
    
        int ans = 0;
        for (int i = 0; i < 31; i++) {
    
            // c[0]: 第 i 位 0 的个数, c[1]: 第 i 位 1 的个数
            vector<int> c(2, 0);
            for (int j = 0; j < n; j++) c[a[j] >> i & 1]++;
    
            // 只有 0 ^ 1 = 1
            ans = (ans + (i64) (1 << i) * c[0] % P * c[1]) % P;
        }
        cout << ans << '\n';
    
        return 0;
    }
    
    • 1

    信息

    ID
    167
    时间
    100ms
    内存
    32MiB
    难度
    6
    标签
    递交数
    29
    已通过
    12
    上传者