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. [远程Call]32位远程多参数带返回调用

    [远程Call]32位远程多参数带返回调用 引子 在Windows上可以使用CreateRemoteThread实现远程Call,但是有不带返回值且只能传递一个参数的限制. 解决思路 将多个参数利用V ...

  2. 企业级低代码平台,通用代码生成平台,Java开源项目(附源码)

    项目介绍 Jeecg-Boot 是一款基于代码生成器的智能开发平台!采用前后端分离架构:SpringBoot,Mybatis,Shiro,JWT,Vue&Ant Design.强大的代码生成器 ...

  3. .NET周刊【9月第2期 2023-09-10】

    国内文章 使用 OpenTelemetry 构建 .NET 应用可观测性(2):OpenTelemetry 项目简介 https://www.cnblogs.com/eventhorizon/p/17 ...

  4. java线程的interrup、tUninterruptibles.sleepUninterruptibly和sleep、wait

    参考: (1)https://blog.csdn.net/qq_36031640/article/details/116696685 (2)https://blog.csdn.net/liuxiao7 ...

  5. SpringBootAdmin_监控

    监控的意义 监控服务状态是否宕机 监控服务运行指标(内存.虚拟机.线程.请求等) 监控日志 管理服务(服务下线) 监控的实施方式 大部分监控平台都是主动拉取监控信息,而不是被动地等待应用程序传递信息 ...

  6. FX3U-3A-ADP模拟量和数字量之间转换

    简单的例子: 0-10V对应0-8,4-20mA对应0-30 以下是对上面例子的详解: 电压: 电压(0-10V) 0-10V对应着数字量0-4000 数字量与变频器HZ量之间的关系是(4000-0) ...

  7. 痞子衡嵌入式:MCUBootUtility v5.3发布,利用XMCD轻松使能外部RAM

    -- 痞子衡维护的 NXP-MCUBootUtility 工具距离上一个大版本(v5.0.0)发布过去4个多月了,期间痞子衡也做过三个小版本更新,但不足以单独介绍.这一次痞子衡为大家带来了全新重要版本 ...

  8. 算法——AcWing算法提高课中代码和题解

    文章目录 第一章 动态规划 (完成情况:64/68) 数字三角形模型 最长上升子序列模型 背包模型 状态机模型 状态压缩DP 区间DP 树形DP 数位DP 单调队列优化DP 斜率优化DP 第二章 搜索 ...

  9. 10. 用Rust手把手编写一个wmproxy(代理,内网穿透等), HTTP内网穿透支持修改头信息

    用Rust手把手编写一个wmproxy(代理,内网穿透等), HTTP内网穿透支持修改头信息 项目 ++wmproxy++ gite: https://gitee.com/tickbh/wmproxy ...

  10. C#学习笔记--复杂数据类型、函数和结构体

    C#基础 复杂数据类型 特点:多个数据变量地一个集合体,可以自己命名 种类:枚举.数组和结构体 枚举:整型常量的集合 数组:任意变量类型的顺序存储的数据集合 结构体:任意变量类型的数据组合成的数据块 ...