[ARC156D] Xor Sum 5
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的更多相关文章
- HDU 4825 Xor Sum(经典01字典树+贪心)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total ...
- 字典树-百度之星-Xor Sum
Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...
- HDU 4825 Xor Sum 字典树+位运算
点击打开链接 Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...
- 2014百度之星第三题Xor Sum(字典树+异或运算)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total ...
- Xor Sum 01字典树 hdu4825
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total S ...
- hdu 4825 Xor Sum (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...
- HDU--4825 Xor Sum (字典树)
题目链接:HDU--4825 Xor Sum mmp sb字典树因为数组开的不够大一直wa 不是报的 re!!! 找了一下午bug 草 把每个数转化成二进制存字典树里面 然后尽量取与x这个位置上不相同 ...
- hdu 4825 Xor Sum trie树
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Proble ...
- hdu 4825 Xor Sum(trie+贪心)
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...
- UVALive4682 XOR Sum
UVALive4682 XOR Sum 题意 给定一个数组, 求连续子序列中异或值最大的值. 题解 假设答案区间为 [L, R], 则答案为 XOR[L, R], 可以将区间分解为 XOR[L,R] ...
随机推荐
- 给你安利一款带有AI功能的数据库管理工具
写在前面 说到数据库管理工具,大家应该不陌生了 小伙伴们应该都用过Navicat.DBever.DataGrip.SQLyog.plsqldeveloper等数据库管理工具 这些工具呢都各自有优缺点. ...
- 非全自研可视化表达引擎-RuleLinK
说在前面 工作中经常会遇到这样的场景: 帮忙把小贝拉门店 商品金额在5w以内,产康订单最多95折. 帮忙把圣贝拉门店 开业时间在6个月内,折扣低于7折要发起审批 帮忙把宁波太平洋店设置独立合同模板 帮 ...
- ios添加库文件
- TIKZ全局样式设置
tikz绘图引擎 TIKZ绘图引擎是基于tex实现,代码极其复杂,每次编写都要单独设置样式,甚是繁琐,如何能够全局设置呢? \begin{tikzpicture}[ auto, % 决策结点 deci ...
- 海量前端后台Java源码模板下载
给大家收集了海量的模板和源码素材,可下载研究和学习使用. 一:前端响应式静态Html5+Css3网页模板(无后台) 1:PC模板:9900套响应式html5+css3网页 ...
- KRPANO资源分析工具下载网展全景图
示:目前分析工具中的全景图下载功能将被极速全景图下载大师替代,相比分析工具,极速全景图下载大师支持更多的网站(包括各类KRPano全景网站,和百度街景) 详细可以查看如下的链接: 极速全景图下载大师官 ...
- 升讯威在线客服系统的并发高性能数据处理技术:PLINQ并行查询技术
我在业余时间开发维护了一款免费开源的升讯威在线客服系统,也收获了许多用户.对我来说,只要能获得用户的认可,就是我最大的动力. 最近客服系统成功经受住了客户现场组织的压力测试,获得了客户的认可. 客户组 ...
- SK 简化流行编程语言对 生成式AI 应用开发的支持
Semantic Kernel[1] 是一个将大型语言模型(LLM)与流行的编程语言相结合的SDK. Microsoft将Semantic Kernel(简称SK)称为轻量级SDK,支持AI LLM的 ...
- Solution Set -「ABC 205」
应该是最近最水的 ABC 了吧. 「ABC 205A」kcal Link. 略 #include <bits/stdc++.h> using ll = long long; #define ...
- 原创基于Scrum框架产研团队运作20问
学习完了 Scrum,实际使用中,是否遇到/思考过下面的问题? Product Owner的老板是谁.谁来给 Product Owner打绩效.考核的标准是啥? Scrum Master 的老板是谁. ...