题解:AT_arc145_e [ARC145E] Adjacent XOR
Camellia2025 · · 题解
solution
考虑把逆向操作,原问题等价于每次可以选择一个
若有解,显然的,有
由于操作
假设我们现在要确定
对于任意的
现在我们需要解决的是,保证在所有
更具体的,我们可以用一个
我们从出现时间晚的线性基元素开始操作,如果当前元素需要调整(不满足上述奇偶性相关),我们只需要操作
更详细的见代码。
code
#include <bits/stdc++.h>
#define int long long
#define For for (int i = 60; i >= 0; i--)
using namespace std;
const int N = 1010;
int a[N], b[N], c[N], pos[70], n;
struct LinearBasic {
int v[70], id[70], tot;
inline bool check (int x) {
For if ((x >> i) & 1)
if (v[i]) x ^= v[i];
else return false;
return true;
}
inline int insert (int x) {
int res = 0;
For if ((x >> i) & 1)
if (v[i]) x ^= v[i], res |= (1ll << id[i]);
else return v[i] = x, id[i] = tot++, res | (1ll << id[i]);
return res;
}
inline void clear () {
memset (v, 0, sizeof (v)), memset (id, 0, sizeof (id)), tot = 0;
}
} p;
vector <int> ans;
inline void work (int x) {
ans.push_back (x);
for (int i = 1; i <= x; i++) b[i] ^= b[i - 1], c[i] ^= c[i - 1];
}
signed main () {
ios :: sync_with_stdio (false), cin.tie (0), cout.tie (0), cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= n; i++)
if (!p.check (a[i] ^ b[i])) return cout << "No", 0;
else p.insert (b[i]);
for (int i = n; i; i--) {
p.clear ();
for (int j = 1; j <= i; j++) {
bool flag = p.check (b[j]);
c[j] = p.insert (b[j]);
if (!flag) pos[__lg (c[j])] = j;
}
int v = p.insert (a[i]);
for (int j = p.tot - 1; j >= 0; j--) {
int res = 0;
for (int k = 1; k <= i; k++) res ^= c[k];
if (((res >> j) & 1) != ((v >> j) & 1)) work (pos[j] + 1);
}
work (i);
}
reverse (begin (ans), end (ans)), cout << "Yes" << endl << ans.size () << endl;
for (int Ans : ans) cout << Ans << " ";
return 0;
}