I used AI to fix my grammar, so this blog might look like it was written by AI.
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



