跳到正文

个人记录

做题记录 25.2.7

szt100309约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年2月7日
收录
2025年12月12日
更新
2026年11月10日
篇幅
约 1 分钟

版本

  1. v1当前

⊙\purple\odot [AGC035C] Skolem XOR Tree

令 11 为根,对于每个偶数 xx(1<x<n1<x< n),将 xx 和 x+1x+1 一起考虑

可构造 x−(x+1)−1−(x+n)−(x+n+1)x-(x+1)-1-(x+n)-(x+n+1),显然 x⊕(x+1)⊕1⊕x=xx\oplus (x+1)\oplus 1\oplus x=x,(x+1)⊕1⊕x⊕(x+1)=x+1(x+1)\oplus 1\oplus x\oplus (x+1)=x+1,即 xx 和 x+1x+1 都满足要求

然后考虑节点 11,令 uu 为任意一个叶子(取 [1,n)[1,n) 的偶数即可),则可令 n+1n+1 接在这个叶子下方,1⊕u⊕(u+1)⊕1=11\oplus u\oplus (u+1)\oplus 1=1,符合要求

当 nn 为偶数时,上述过程没有加入 nn

令 tt 为 nn 的任意一个二进制位(实现时取 lowbit⁡\operatorname{lowbit} 即可),则可将 nn 和 n+nn+n 分别接在 t+1t+1 和 n−t+nn-t+n 下,n⊕(t+1)⊕1⊕(n−t)⊕n=nn\oplus (t+1)\oplus 1\oplus (n-t)\oplus n=n,符合要求

时间复杂度 O(n)O(n)

代码

参考

原文