E - Alternating String Editorial by TOMWT

An interesting alt solution

After reading the string from input, do the following operation:

  • \(s_i\gets s_i\operatorname{xor}(i\bmod 2)\)

Then a string is good \(\iff\) all characters are the same.

Use a datastructure to maintain sum of ranges.

Implmentation

posted:
last update: