跳到正文

题解

P12025

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

文章信息

发布
2025年8月26日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟
获赞
2
题目
P12025

版本

  1. v1当前

此片题解为口胡,具体代码参考题解区。

注意到 popcount\text{popcount} 与 ⊕\oplus,考虑将 kk 拆位作为突破口。

popcount(a1)⊕ popcount(a2)⊕⋯⊕ popcount(aN)=K\text{popcount}(a_1) \oplus \text{ popcount}(a_2) \oplus \dots \oplus \text{ popcount}(a_N) = K。

容易想到将 kk 的每一位对应下来变成 popcount\text{popcount},例如 5=(101)25=(101)_2,那么有 popcount(a1)=22\text{popcount}(a_1)=2^2,popcount(a2)=20\text{popcount}(a_2)=2^0,此时有 popcount(a1)⊕ popcount(a2)=k\text{popcount}(a_1) \oplus \text{ popcount}(a_2)=k。考虑 popcount(ai)=D\text{popcount}(a_i)=D 的最小 aia_i,易得 ai=2D−1a_i=2^D-1。

我实在是懒,记 ⊕i=1n=popcount(a1)⊕ popcount(a2)⊕⋯⊕ popcount(an)\displaystyle \oplus_{i=1}^n=\text{popcount}(a_1) \oplus \text{ popcount}(a_2) \oplus \dots \oplus \text{ popcount}(a_n)。

记 g=popcount(k)g=\text{popcount}(k),S=∑i=1gaiS=\sum_{i=1}^g a_i,Q=M−SQ=M-S,此时的 QQ 表示的是距离需要构造的 ∑i=1nai=m\sum_{i=1}^n a_i=m 还差多少,为 aia_i 接下来填充做总体概览,但是为了满足 ⊕i=1nai=k\oplus _{i=1}^n a_i=k,考虑加入的 aia_i 是否满足。

Q=0Q=0,输出即可。

Q=1Q=1,考虑需要给 SS 再配上 11,注意到 22 和 11 的 popcount\text{popcount} 相等,考虑将 ag=1a_g=1 换成 22 即可,注意 aga_g 如果不为 11,无解。

QQ 为偶数,考虑构造两个相同的数使得 ⊕\oplus 值不变,直接 m2\frac{m}{2} 即可。考虑 QQ 为奇数,因为 11 和 22 的 popcount\text{popcount} 相等,将 1+2=31+2=3 从 QQ 中提出去,于是退化为偶数的情况,即 QQ 为奇数时可加入 [1,2,m−32,m−32][1,2,\frac{m-3}{2},\frac{m-3}{2}]。

原文
存档评论4 条抓取于