Comments

Because this competition is prepared by one of luogu's (a Chinese cp website) team of problem setters (called WdOI). Of course this comment is just joking, please don't take it seriously.(however for myself Chinese rounds are too terrible I always get negative rating changes :(

So, how Elegia's mind works?

however actually B can be solved in $$$O(n+q)$$$ without using segment tree

actually you can solve it in $$$O(2^{17}\times 17^2)$$$ by using SOS dp or fast walsh transform.The solution is similar to yours.

My submission

First,it's rating.It's because they would like to practice since there is no div.1 for it.

It is the same problem as a Chinese contest's div1 A/div2 C.

However the edge cases are different for different (wrong) solutions, which makes it difficult to decide which should get a small penalty.

however when I see this problem I immediately use strongly connected components to solve the problem instead of guessing conclusions although it took me a lot of time :(

In fact it's the first test that the answer isn't all '1' or only one '1'.

It's easy to see that the coloring is valid only when the number of 'BB' and 'WW' is the same,except for when there is only 'BW' and 'WB'. The first case can be calculated by using generating functions.(Hint: $$$[x^k](1+x)^n=\dbinom{n}{k}$$$ ) The second case is quite trivial, then the complexity is just $$$O(n)$$$ or $$$O(n\log n)$$$ if you calculate the reciprocal using quickpow.

In fact,you can find a legendary grandmaster in 10 rounds.

Flakire can get Master in only 2 rounds. So orz Flakire.