题解:CF1614C Divan and bitwise operations

· · 题解

考虑计算贡献。令序列 a 中有 cnt 个数的第 k 位为 1。

对于一个子序列的异或和,如果第 k 为为 1,则说明有奇数个 1 和任意个 0 异或起来,则这样的子序列有

\begin{aligned} \left(\binom{cnt}{1}+\binom{cnt}{3}+\ldots\right)\times 2^{n-cnt} &=2^{cnt-1}\times 2^{n-cnt}\\ &=2^{n-1} \end{aligned}

贡献即为 2^{n-1}\times 2^{k}。

由于我们只关心序列中哪些位可以为 1,所以把所有 x 或起来即可,设为 S,则答案为 S\times 2^{n-1}。 :::success[Code]

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int maxn=1e5+10;
const int p=1e9+7;
int n;
int qpow(int x,int k){
    int base=1;
    while(k){
        if(k&1) base=base*x%p;
        x=x*x%p;
        k>>=1;
    }
    return base;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        int n,m,s=0;
        cin>>n>>m;
        for(int i=1;i<=m;i++){
            int l,r,x;
            cin>>l>>r>>x;
            s|=x;
        }
        cout<<s*qpow(2,n-1)%p<<endl;
    }
    return 0;
}

:::