P12025
nytyq
·
·
题解
此片题解为口胡,具体代码参考题解区。
注意到 \text{popcount} 与 \oplus,考虑将 k 拆位作为突破口。
容易想到将 k 的每一位对应下来变成 \text{popcount},例如 5=(101)_2,那么有 \text{popcount}(a_1)=2^2,\text{popcount}(a_2)=2^0,此时有 \text{popcount}(a_1) \oplus \text{ popcount}(a_2)=k。考虑 \text{popcount}(a_i)=D 的最小 a_i,易得 a_i=2^D-1。
我实在是懒,记 \displaystyle \oplus_{i=1}^n=\text{popcount}(a_1) \oplus \text{ popcount}(a_2) \oplus \dots \oplus \text{ popcount}(a_n)。
记 g=\text{popcount}(k),S=\sum_{i=1}^g a_i,Q=M-S,此时的 Q 表示的是距离需要构造的 \sum_{i=1}^n a_i=m 还差多少,为 a_i 接下来填充做总体概览,但是为了满足 \oplus _{i=1}^n a_i=k,考虑加入的 a_i 是否满足。
$Q=1$,考虑需要给 $S$ 再配上 $1$,注意到 $2$ 和 $1$ 的 $\text{popcount}$ 相等,考虑将 $a_g=1$ 换成 $2$ 即可,注意 $a_g$ 如果不为 $1$,无解。
$Q$ 为偶数,考虑构造两个相同的数使得 $\oplus$ 值不变,直接 $\frac{m}{2}$ 即可。考虑 $Q$ 为奇数,因为 $1$ 和 $2$ 的 $\text{popcount}$ 相等,将 $1+2=3$ 从 $Q$ 中提出去,于是退化为偶数的情况,即 $Q$ 为奇数时可加入 $[1,2,\frac{m-3}{2},\frac{m-3}{2}]$。