跳到正文

个人记录

ARC

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

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e2+5,V=1024;
int n;
long long k;
int cnt[N][V<<1];
long long dp[N][V<<1];
long long a[N];
int p[N];
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	int tot=0;
	while(k){
		p[++tot]=(k&1);
		k>>=1;
	}
	if(p[1]==1){
		for(int i=1;i<=n;i++){
			dp[1][a[i]>>1]^=(a[i]&1);
			cnt[1][a[i]>>1]^=1;
		}
	}else{
		dp[1][0]=0;
		cnt[1][0]=1;
	}
	for(int i=1;i<tot;i++){
		for(int j=0;j<V;j++){
//			cout<<i<<' '<<j<<' '<<cnt[i][j]<<endl;
			if(p[i+1]==0){
				dp[i+1][j>>1]^=dp[i][j];
				dp[i+1][j>>1]^=(((cnt[i][j]&(j&1))*1LL)<<i);
				cnt[i+1][j>>1]^=cnt[i][j];
				continue;
			}
			for(int id=1;id<=n;id++){
				dp[i+1][(j+a[id])>>1]^=dp[i][j];
				dp[i+1][(j+a[id])>>1]^=(((cnt[i][j]&((j+a[id])&1))*1LL)<<i);
				cnt[i+1][(j+a[id])>>1]^=cnt[i][j];
//				cout<<id<<' '<<i<<' '<<j<<' '<<i+1<<' '<<((j>>1)+(a[id]>>1))<<' '<<cnt[i][j]<<' '<<cnt[i+1][(j>>1)+(a[id]>>1)]<<endl;
			}
		}
	}
	long long ans=0;
	for(int i=0;i<V;i++){
//		cout<<tot<<' '<<i<<' '<<cnt[tot][i]<<endl;
		ans^=((1LL*cnt[tot][i]*i)<<tot)^dp[tot][i];
	}
	cout<<ans<<endl;
	return 0;
}
原文