跳到正文

题解

题解:CF1614C Divan and bitwise operations

__EternalLife__约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年8月11日
收录
2026年8月13日
更新
2026年11月13日
篇幅
约 2 分钟
题目
CF1614C

版本

  1. v1当前

考虑计算贡献。令序列 aa 中有 cntcnt 个数的第 kk 位为 11。

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

((cnt1)+(cnt3)+…)×2n−cnt=2cnt−1×2n−cnt=2n−1\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}

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

由于我们只关心序列中哪些位可以为 11,所以把所有 xx 或起来即可,设为 SS,则答案为 S×2n−1S\times 2^{n-1}。

Code
C++
#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;
}
原文