This problem is about finding patterns and tests one’s familiarity with xor. In fact, I had once been very close to the correct solution. But I was fixated on my past experience solving interval problems with segment trees, trying to figure out what information each node should record. As a result, I went further and further off track.
To summarize, the pattern is: The problem gives the definition of xor-even. From the properties of xor, we have:
odd xor odd -> even
odd xor even -> odd
even xor even -> even
To make the final xor-even, the number of odd elements in the interval must be even. A very direct idea follows. Count the number of odd elements. If it is even, the longest interval is the length of the whole array. If it is odd, remove either the head or the tail and find the longer one.