版本比较
P14936 「FAOI-R10」别样的 mex 大战题解
正文
增加 2 行删除 2 行
23 行未改动2425262728282930313234 行未改动6768697071717273747523 行未改动23 行未改动
- 但需确保 $x \neq M$,否则 $M$ 会出现,导致 $M' > M$。当 $S \neq 0$ 时,$x = S \oplus M$ 一定不等于 $M$(因为如果 $S \oplus M = M$,则 $S=0$,矛盾)。因此,当 $S \neq 0$ 时,我们可以添加 $x = S \oplus M$,此时新序列的 $\operatorname{mex}$ 仍为 $M$,异或和为 $M$,满足条件。
##### 3. 添加两个数($k=2$)
- 当 $S = 0$ 且 $M \neq 0$ 时,无法通过添加一个数满足条件(因为此时 $x = S \oplus M = M$,添加 $M$ 后 $M$ 出现,$M' > M$,而异或和为 $M$,不相等)。因此需要添加两个数 $x$ 和 $y$。
- 添加后异或和为 $x \oplus y$(因为 $S=0$),新序列的 $\operatorname{mex}$ 为 $M'$。我们希望 $M' = M$,即保持 $\operatorname{mex}$ 不变,这需要 $x$ 和 $y$ 都不等于 $M$。同时需要 $x \oplus y = M$。
34 行未改动 sum ^= x; s.insert(x); } int mex = 0; while (s.count(mex)) mex++; while (s.count(mex)) mex++; if (sum == mex) { cout << "0\n\n"; } else if (sum != 0) { cout << "1\n" << (sum ^ mex) << "\n";23 行未改动