Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
First classify losing positions. A move must have XOR , but the bound is just a numeric bound, not a bit-submask restriction.
If a position has at most one positive pile, no nonzero move can have XOR . The XOR of a single positive number is still positive.
If there are at least two positive piles, the position is winning: either remove everything when the total XOR is , or do the usual highest-bit XOR trick to leave exactly one pile positive.
So Alice only needs to count moves that leave either the all-zero array or an array with exactly one positive element.
Let . The all-zero target contributes if . If only pile survives, then the removed amount from it is forced to be , so count it iff .
Do not start by trying to do bit DP over the chosen . The easy way is to ask which positions are losing.
A position with at most one positive pile is losing. Any valid would also have at most one positive component, and the XOR of one positive number cannot be .
Now take a position with at least two positive piles. It is winning because it can move to one of those losing positions.
Let
If , remove everything: choose for all . Then the removed XOR is , and the next position is all zero.
If , let be the highest set bit of . Pick an index where has bit set. Then
because the highest changed bit is cleared. Set
and for every , set
The XOR of the removed array is
Also , so pile stays positive, and every other pile becomes . The target has exactly one positive pile, so it is losing.
Therefore the losing positions are exactly the arrays with at most one positive element. Nice: the game looks like XOR chaos, then folds into a one-line shape.
Now count Alice's winning first moves. Since all input are positive, if the answer is immediately .
Assume . A winning move must leave either zero positive piles or exactly one positive pile.
The all-zero target has for all , so it is legal exactly when
This contributes move if .
For a target where only pile remains positive, all other piles must be fully removed:
The value of is forced by the XOR condition:
For pile to remain positive, we need
That is exactly
For each such index , there is exactly one winning move. If the inequality fails, no move with only pile positive exists.
So for ,
The answer is at most , but we still print it modulo because the statement asks for it.
Complexity is per test case and memory to store the array. The sum of is , so this is comfortably inside the limits.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
int xr = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
xr ^= a[i];
}
if (n == 1) {
cout << 0 << '\n';
continue;
}
ll ans = (xr == 0);
for (int x : a) {
if ((xr ^ x) < x) ans++;
}
cout << ans % MOD << '\n';
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
int xr = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
xr ^= a[i];
}
if (n == 1) {
cout << 0 << '\n';
continue;
}
ll ans = (xr == 0);
for (int x : a) {
if ((xr ^ x) < x) ans++;
}
cout << ans % MOD << '\n';
}
return 0;
}