题解:CF1572B Xor of 3
好题。
操作比较奇怪,我们在前缀异或序列上考虑问题,不难发现操作相当于
奇数位置偶数位置相对独立,然后你发现偶数位置的
显然奇数位置必须有一个
注意到
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+114;
int a[maxn];
int n;
void work(){
cin>>n;
int st=1;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]^=a[i-1];
if(i%2==1) st&=a[i];
}
if(a[n]==1){
cout<<"NO\n";
return ;
}
if(st==1){
cout<<"NO\n";
return ;
}
cout<<"YES\n";
vector<int> opt;
int key=1;
for(int i=1;i<=n;i++){
if(i%2==1&&a[i]==0) key=i;
}
for(int i=key-2;i>=1;i-=2){
if(a[i]==1) opt.push_back(i),a[i]=0;
}
for(int i=key+2;i+1<=n;i+=2){
if(a[i]==1) opt.push_back(i-1),a[i]=0;
}
for(int i=1;i+2<=n;i+=2){
opt.push_back(i);
}
cout<<opt.size()<<'\n';
for(int x:opt) cout<<x<<" ";
cout<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--) work();
return 0;
}