CF1572B 题解
NobodyThere · · 题解
提供一种比较好想好写,不容易错的方法。教你将 *2500 的题做成 *1500
题目链接
思路
显然,当存在奇数个
证明:设对
更进一步地,记
给定
这就很好做了。显然每次赋值都只能在下标奇偶性相同的相邻位置上进行,且不能给
代码实现
#include <cstdio>
int T, n, a[200007], s[200007], ans[200007], tot, idx;
int main() {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for(int i = 1; i <= n; i++)
s[i] = s[i - 1] ^ a[i];
if(s[n]) {
puts("NO"); continue;
}
tot = 0, idx = 0;
for(int i = 1; i <= n; i += 2) {
if(!s[i]) {
idx = i; break;
}
}
if(!idx) {
puts("NO"); continue;
}
for(int i = idx - 2; i >= 1; i -= 2)
ans[++tot] = i;
for(int i = idx + 2; i < n; i += 2)
ans[++tot] = i - 1;
for(int i = 2; i < n; i += 2)
ans[++tot] = i - 1;
puts("YES");
printf("%d\n", tot);
for(int i = 1; i <= tot; i++)
printf("%d ", ans[i]);
puts("");
}
return 0;
}