I used AI to fix my grammar, so this blog might look like it was written by AI. You can read the Chinese version of this blog here.
Upd 2026.08.30: Replaced with a cleaner proof. Thanks to PhirainEX for the inspiration!
This is an alternative solution to 2241F - A Bit Odd, which differs from the editorial.
Obviously, if the remaining sequence length is $$$\le 1$$$, the number of inversions is $$$0$$$, making it a P-state (a losing state for the current player). Now, let's consider the following three states:
- If the initial number of inversions is odd, Alice can simply remove the entire sequence, leaving an empty sequence. Thus, this is an N-state (a winning state for the current player), and Alice wins.
- If the initial number of inversions is even, and there exists an index $$$i$$$ such that the number of inversions becomes odd after removing $$$s_i$$$ (which is equivalent to saying $$$s_i$$$ contributes an odd number of inversions), Alice can remove everything except $$$s_i$$$. This leaves a sequence of length $$$1$$$, so this is also an N-state, and Alice wins.
- If neither of the above conditions is met, we can make an observation and guess that Bob wins (P-state).
Proof
Since we are dealing with a $$$01$$$-string, maintaining the number of inversions only requires prefix sums, so data structures like a Fenwick tree are unnecessary.
Implementation








Auto comment: topic has been updated by WhiteCatBlackHat (previous revision, new revision, compare).
did it the same way.submission
wait it wasn't the main solution I thought it is the main solution as I also did same thing
A similar alternative solution is to see that winning moves will remove as many inversions as possible from the original string, which can be accomplished by removing all 1s or all 0s.
For example, consider removing all the 1s from the original string. If there exists $$$s[i]=0$$$ such that there are an odd number of preceeding ones, we can remove all ones from the string immediately by selecting this 0 and all other ones. Similar logic holds for 0, but using suffix instead of prefix.
If all prefixes/suffixes have even sum, Alice will be forced to make a move that causes either count of ones or count of zeroes to be odd, and Bob will use the same strategy to win.
Auto comment: topic has been updated by WhiteCatBlackHat (previous revision, new revision, compare).