正文
增加 4 行删除 4 行
12345678910 行未改动20212223242526272815 行未改动## [P14223 [ICPC 2024 Kunming I] 乐观向上](https://www.luogu.com.cn/problem/P14223)## 思路简述因为对于所有 $0 \le i < n$,都有 $p_0 \oplus p_1 \oplus \cdots \oplus p_i > 0$。所以当填入 $p_i$ 时,$p_0 \oplus p_1 \oplus p_2 \cdots \oplus p_{i-1} \neq p_i$。又因为要让 $p_0, p_1, p_2 \cdots, p_{n-1}$ 字典序最小。所以要每次要取能取的最小值。不难想到,我们可以用一个链表维护当前那个数为最小值。**注意:当前面的异或值为最小值时,应选用次小值。**## AC代码```cpp#include<bits/stdc++.h>10 行未改动h=0;int sum=0,f=1;for (int i=1;i<=n;i++) {if (h==sum) {if (nx[h]==n) f=0;int t=nx[h];ans[i]=t;sum^=t;nx[h]=nx[t];15 行未改动12345678910 行未改动20212223242526272815 行未改动## [P14223 [ICPC 2024 Kunming I] 乐观向上](https://www.luogu.com.cn/problem/P14223)## 思路简述因为对于所有 $0 \le i < n$,都有 $p_0 \oplus p_1 \oplus \cdots \oplus p_i > 0$。所以当填入 $p_i$ 时,$p_0 \oplus p_1 \oplus p_2 \cdots \oplus p_{i-1} \neq p_i$。又因为要让 $p_0, p_1, p_2 \cdots, p_{n-1}$ 字典序最小。所以要每次要取能取的最小值。不难想到,我们可以用一个链表维护当前那个数为最小值。**注意:当前面的异或值为最小值时,应选用次小值。**## AC代码```cpp#include<bits/stdc++.h>10 行未改动h=0;int sum=0,f=1;for (int i=1;i<=n;i++) {if (h==sum) {if (nx[h]==n) f=0;int t=nx[h];ans[i]=t;sum^=t;nx[h]=nx[t];15 行未改动