We'd like to thank you all for participating in the contest, and hope you enjoyed it. Any feedback would be appreciated!
2183A — Binary Array Game
Time complexity: $$$O(\sum n)$$$.
2183B — Yet Another MEX Problem
2183C — War Strategy
2183D1 — Tree Coloring (Easy Version)
2183D2 — Tree Coloring (Hard Version)
2183E — LCM is Legendary Counting Master
2183F — Jumping Man
Let $$$f_{i,j}$$$ represent the number of ways to choose two strings located at nodes $$$i$$$ and $$$j$$$, respectively, within their subtrees. Clearly, $$$f_{i,j}$$$ has a non-zero value only if $$$c_i = c_j$$$, where $$$c$$$ denotes the string sequence.
Then, $$$f_{p,q}$$$ contributes to $$$f_{i,j}$$$ if and only if $$$p$$$ is in the subtree of $$$i$$$ and $$$q$$$ is in the subtree of $$$j$$$. By performing a depth-first search (DFS) on the tree and marking timestamps, the $$$(dfn_p, dfn_q)$$$ pairs of contributing $$$f_{p,q}$$$ must form a rectangle. Sorting by $$$dfn$$$ and computing suffix sums suffices.
The time complexity is $$$O(n^2)$$$.
It can be observed that the sizes of the sets returned after querying \texttt{L} and \texttt{LR} are the same. The proof is as follows: After querying \texttt{LR}, the positions of the surviving snakes are exactly their initial positions. Since the relative positions of all snakes remain unchanged, operating \texttt{R} after \texttt{L} will never cause two snakes to collide. Hence, the sizes of the returned sets are identical.
By establishing a one-to-one correspondence with the initial coordinates, we can easily deduce the speeds of all snakes that survive after querying \texttt{L}.
At this point, we only lack the speeds of the snakes that died after querying \texttt{L}. A simple case analysis reveals the following scenarios (where the first number on the right represents the speed of the snake that died after querying \texttt{L}, and ``_'' indicates no snake at that initial position): \begin{itemize} \item \texttt{01} \item \texttt{02} \item \texttt{0_2} \item \texttt{12} \end{itemize}
These cases can be resolved through direct casework, though the implementation may be somewhat cumbersome. Therefore, we consider a more concise approach.
First, we aim to determine the speeds of some snakes with speed $$$2$$$. For the position and speed of such a snake, the following cases allow direct determination: \begin{itemize} \item The previous snake is at a distance of $$$1$$$ and has a confirmed speed of $$$1$$$. \item The previous snake is at a distance of $$$1$$$ and has an unconfirmed speed. Here's why the speed of the current snake is determined in this case: \begin{itemize} \item If the previous snake's speed is $$$0$$$, it will definitely not be killed in a collision, so this scenario is impossible. \item If the previous snake's speed is at least $$$1$$$, then the current snake must have a speed of at least $$$2$$$ to collide with it. Thus, the current snake's speed is at least $$$2$$$. \end{itemize} \item The previous snake is at a distance of $$$2$$$ and has a confirmed speed of $$$0$$$. \end{itemize}
The above casework naturally excludes the scenarios \texttt{0_2} and \texttt{12}.
Now, only the cases \texttt{01} and \texttt{02} remain. It can be observed that the only indistinguishable scenarios are \texttt{010} and \texttt{020}. Therefore, we can initially disregard such cases, first find a valid solution, and then check whether this solution exhibits such a scenario.
Otherwise, since the snake immediately after the current one has a speed of at least $$$1$$$ (in cases with a unique solution), the position this snake would reach after moving without obstacles is exactly the position of the first snake whose position is $$$\ge$$$ the current snake's position after querying \texttt{R}. If this snake does not encounter any other snake while moving right, its position can also be directly determined. Thus, we can use this method to determine the speeds of all snakes.
Time complexity: $$$O(\sum n)$$$ or $$$O(\sum n \log n)$$$.



