I feel like I've done this before. Clearly the answer has nothing to do with the characters. We need to fix the leftmost subsequence, then enumerate the last position, and we get the result (subsequence \(T\), target string length \(n\)):
Continue reading →Chinese original · English translation by Claude Opus 5.5
First, we can see that this thing can be viewed as a bipartite graph model, except that now we need to compute its maximum matching quickly. Then, by Hall's theorem, if for any left vertex \(x \in U, |U| < |V|\), the set \(M\) of right endpoints it connects to satisfies \(|M| > |U|\), then a perfect matching exists.
This problem has a property: no interval contains another. So satisfying Hall's theorem actually just requires that for every segment, \(\sum_{i = l}^r b_i \leq \sum_{i = L[l]}^{R[r]} a_i\) holds, where \(b_i\) means that for the \(i\)-th segment we take \(b_i\) stones.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First there's a brute force: for \(l\) within \(10^7\) you can just do two-pointers; if it's above \(10^7\), you notice that \(f(r) - f(l) \leq 1\). Then we can consider enumerating the length of this contiguous segment, \(L = x + y\), where \(x\) is the part with \(i\) \(0\)s and \(y\) is the part with \(i + 1\) \(0\)s. There's an equation: \(x \times i + y \times (i + 1) = (x + y)i + y = Li + y = S\). So when enumerating \(L\), if \(S \bmod L \equiv 0\), that means \(y = 0\), and you count the left endpoints within \(10^i\) (it's really just subtracting an extra \(L - 1\)). If \(S \bmod L \neq 0\), that means \(x, y\) are determined, so you just ++.
Continue reading →Chinese original · English translation by Claude Opus 5.5
A DP. Consider constructing it in reverse: from \(0\) to \(X\). The process will surely end up as adding and subtracting a bit first, then dividing, and so on and so forth.
Continue reading →Chinese original · English translation by Claude Opus 5.5
For 0, we just need the final answer to be 0. So we maintain things from back to front: maintain the linear basis formed by combining the values at the \(0\) positions, and each time we reach a \(1\) position, just query it in there. If it isn't found, then for \(1\), the later \(0\)s aren't enough to cancel that operation, so we can declare \(1\) the winner, and vice versa.
Continue reading →Chinese original · English translation by Claude Opus 5.5
Notice that \(f(x)\) brings no benefit for any number with a square factor, so we only consider \(f(x) = \prod_{i = 1}^m p_i\). Then it is easy to see that \(f(x) = \prod_{r = 0}^m (-1)^{2^{(r - 1)}}\), so:
\[f(x) = \begin{cases} -1, x \in primes or x = 1 \\ 1, otherwise \end{cases}\]
Continue reading →Chinese original · English translation by Claude Opus 5.5