Problem Statement

You are given a sequence of $N$ non-negative integers $A=(A_1,A_2,\dots,A_N)$ and a positive integer $K$.

Find the bitwise $\mathrm{XOR}$ of $\displaystyle \sum_{i=1}^{K} A_{X_i}$ over all $N^K$ sequences of $K$ positive integer sequences $X=(X_1,X_2,\dots,X_K)$ such that $1 \leq X_i \leq N\ (1\leq i \leq K)$.

What is bitwise $\mathrm{XOR}$?

The bitwise $\mathrm{XOR}$ of non-negative integers $A$ and $B$, $A \oplus B$, is defined as follows:

  • When $A \oplus B$ is written in base two, the digit in the $2^k$'s place ($k \geq 0$) is $1$ if exactly one of the digits in that place of $A$ and $B$ is $1$, and $0$ otherwise.

For example, we have $3 \oplus 5 = 6$ (in base two: $011 \oplus 101 = 110$).

Generally, the bitwise $\mathrm{XOR}$ of $k$ non-negative integers $p_1, p_2, p_3, \dots, p_k$ is defined as $(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)$. We can prove that this value does not depend on the order of $p_1, p_2, p_3, \dots, p_k$.

Constraints

  • $1 \leq N \leq 1000$
  • $1 \leq K \leq 10^{12}$
  • $0 \leq A_i \leq 1000$
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$N$ $K$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Print the answer.


Sample Input 1

2 2
10 30

Sample Output 1

40

There are four sequences to consider: $(X_1,X_2)=(1,1),(1,2),(2,1),(2,2)$, for which $A_{X_1}+A_{X_2}$ is $20,40,40,60$, respectively. Thus, the answer is $20 \oplus 40 \oplus 40 \oplus 60=40$.


Sample Input 2

4 10
0 0 0 0

Sample Output 2

0

Sample Input 3

11 998244353
314 159 265 358 979 323 846 264 338 327 950

Sample Output 3

236500026047

看着样例,会发现根据异或的性质,很多情况都会被约掉。

那么推一波生成函数,最终 \(S\) 是否有有贡献,就要看 \([x^S](\sum\limits_{i=1}^nx^{a_i})^K\) 为奇数还是偶数。

\((x_1+x_2+\cdots+x_n)^2=x_1^2+x_2^2+\cdots+x_n^2+2(\cdots)=x_1^2+x_2^2+\cdots+x_n^2\),

同理,\((x_1+x_2+\cdots+x_n)^{2^k}=x_1^{2^k}+x_2^{2^k}+\cdots+x_n^{2^k}\)

可以对 \(K\) 进行二进制分解后套入这个式子,然后考虑他的实际意义。此时将 \(K\) 拆为 \(2^{k_1}+2^{k_2}+\cdots+2^{k_n}\),那么将题目改为如果将 \(K\) 个数分成很多段,每一段的长度都是2的正整数幂,且填一样的数,答案不变。

这个结论也有感性的理解方式。可以通过二进制分组的方式,给所有不满足这个要求的序列某两个数交换一下,和不变,异或和消掉。所有不满足要求的序列都能一一对应上。

所以知道这个后,可以数位 dp。定义 \(dp_{i,j}\) 为考虑到第 \(i\) 位,目前所有进位+填入的 \(a\) 的和为 \(j\) 的方案数。如果 \(i\) 是 \(K\) 二进制分组后的部分,那么就可以枚举新选什么数。同时统计答案时,注意到这里真正的方案数要乘上 \(n\) 的一个次方,所以如果 \(n\) 为奇数或者这里是 \(K\) 的最大的一个二进制位时,才会统计入答案。

#include<bits/stdc++.h>
using namespace std;
const int N=4005;
long long k,ans;
int n,a[N],dp[55][N];
int main()
{
scanf("%d%lld",&n,&k);
for(int i=1;i<=n;i++)
scanf("%d",a+i);
dp[0][0]=1;
for(int i=0;i<=50;i++)
{
for(int j=0;j<1024;j++)
{
if(!dp[i][j])
continue;
if(k>>i&1)
{
for(int p=1;p<=n;p++)
{
if((j+a[p]&1)&&(n&1||(1LL<<i+1)>k))
ans^=1LL<<i;
dp[i+1][j+a[p]>>1]^=1;
}
}
else
{
if((j&1)&&(n&1||(1LL<<(i+1))>k))
ans^=1LL<<i;
dp[i+1][j>>1]^=1;
}
}
}
printf("%lld",ans);
return 0;
}

[ARC156D] Xor Sum 5的更多相关文章

  1. HDU 4825 Xor Sum(经典01字典树+贪心)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total ...

  2. 字典树-百度之星-Xor Sum

    Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...

  3. HDU 4825 Xor Sum 字典树+位运算

    点击打开链接 Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) ...

  4. 2014百度之星第三题Xor Sum(字典树+异或运算)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total ...

  5. Xor Sum 01字典树 hdu4825

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total S ...

  6. hdu 4825 Xor Sum (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...

  7. HDU--4825 Xor Sum (字典树)

    题目链接:HDU--4825 Xor Sum mmp sb字典树因为数组开的不够大一直wa 不是报的 re!!! 找了一下午bug 草 把每个数转化成二进制存字典树里面 然后尽量取与x这个位置上不相同 ...

  8. hdu 4825 Xor Sum trie树

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Proble ...

  9. hdu 4825 Xor Sum(trie+贪心)

    hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...

  10. UVALive4682 XOR Sum

    UVALive4682 XOR Sum 题意 给定一个数组, 求连续子序列中异或值最大的值. 题解 假设答案区间为 [L, R], 则答案为 XOR[L, R], 可以将区间分解为 XOR[L,R] ...

随机推荐

  1. MIT6.s081/6.828 lectrue5/6:System call entry/exit 以及 Lab4 心得

    这篇博客主要复习 lecture05:GDB calling conentions 和 lecture06:System call entry/exit 的内容,外加 Lab4:traps 的心得 前 ...

  2. 使用“文心一言”编写技术博文《搭建企业知识库:基于 Wiki.js 的实践指南》

    百度于8月31日零点宣布,文心一言率先向全社会全面开放.我也是立即体验了下,感觉还不错.下面分享一下,如何使用"文心一言"写一篇技术博客. Step 01 生成文案主体 可以对文心 ...

  3. Go学习笔记3

    九.错误处理 1.defer+recover机制处理异常错误 展示错误: 发现:程序中出现错误/恐慌以后,程序被中断,无法继续执行. 错误处理/捕获机制: 内置函数recover: 2.自定义错误 需 ...

  4. python基础:元组(tuple)列表(list)介绍

    一,元组 1.元组的创建(可以把元组看作一个容器,任何数据类型都可以放在里面)通过赋值方法创建元组In [5]: t = ("hello",2.3,2,True,{1:" ...

  5. 探秘移动端BI:发展历程与应用前景解析

    什么是移动端BI 维基百科 上对于 移动端商业智能的定义是这样的 > Mobile BI is a system that presents historical and real-time i ...

  6. 贝塞尔曲线的切线及其AABB问题

    贝塞尔曲线的切线及其AABB问题 先聊点别的 2023 年抖音上居然还看到很多前端培训 各种直播前端教学(虽然是录播)但看起来还是有大批前往前端卷啊 说明了什么,很可能说明其它行业更难卷 这不是行业不 ...

  7. 开发app软件成本计算参考

    目录 1. 设计成本 2. 前端开发成本 3. 后端开发成本 4. 测试成本 5. 上架试运营成本 app软件开发已成为人们生活中不可或缺的一部分.无论是在娱乐.通讯.信息.健康等方面,都有数不清的a ...

  8. Use Closures Not Enumerations

    http://c2.com/  Use Closures Not Enumerations I was really disappointed when this turned out not to ...

  9. RK3588平台产测之ArmSoM-W3软硬件重启测试

    1. 简介 专栏总目录 ArmSoM团队在产品量产之前都会对产品做几次专业化的功能测试以及性能压力测试,以此来保证产品的质量以及稳定性 优秀的产品都要进行多次全方位的功能测试以及性能压力测试才能够经得 ...

  10. PHP-basename

    basename 定义: basename() 函数返回路径中的文件名部分. 语法: basename(path,suffix) 参数 描述 path 必需.规定要检查的路径 suffix 可选.规定 ...