Thinking about this problem's properties directly is hard, because if you go greedy, finding two cliques of similar size doesn't have any nice property. We can consider building the complement graph. If it is a bipartite graph, then its left and right parts can serve exactly as the two states in the problem. However, notice that it isn't guaranteed to be a connected bipartite graph, so we can piece the two states together from several connected components. Then we can mess around with a knapsack and just compute the answer at the end. (So there's no need to greedily construct two cliques of similar size; just compute all of them).
Continue reading →Chinese original · English translation by Claude Opus 5.5
We notice that every point can only go so far to the left and to the right; computing this gives \((x_i, y_i)\), where \(x\) stands for the left and \(y\) for the right. Then, putting this thing on a scatter plot, we find that our essentially different operations are a monotonically non-decreasing polyline: because if we take \(x\) as this path’s “longest leftward move distance” and \(y\) as this path’s “longest rightward move distance”, then this polyline passing through the \(x\) frame or the \(y\) frame of any point will make this thing go GG, so by counting such polylines we can count the corresponding schemes.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First, the \(n - 1\) pairs represent the shape of this tree-shaped directed graph. Let's first consider the out-tree case: the timestamp of a subtree's root has to be earlier than those of all the child nodes, so we can consider merging directly with the knapsack method. If there are reversed edges, then we can consider inclusion–exclusion: enumerate the number of reversed relations and multiply by an inclusion–exclusion coefficient of \(-1\), and that's it.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First, we transform \((-1)^b\). It turns out it can be turned into something number-theoretic: \((-1)^b = 1 - 2(b \bmod 2)\), so we can massage the expression a bit:
Continue reading →Chinese original · English translation by Claude Opus 5.5
I thought about it for ages and still had no idea how to characterize the state; later I found it could be turned into a generalized problem, and then it was much easier to understand.
Consider subtracting not strictly the minimum but an arbitrary value, while still reaching the result the problem asks for. This problem certainly can't be better, and its optimal solution can directly serve as the optimal solution to this problem.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First, we know it has to be SAM, but you and I both know the shape of the tree changes during the linear-time construction, so there is no way to maintain the sum of node weights at the root. So just throw in an LCT to handle it.
Continue reading →Chinese original · English translation by Claude Opus 5.5
The main thing is still to pay attention to designing the states.
We call \((-1, x)\) a single pair, and \((-1, -1)\) a double pair. We can try filling in the numbers from largest to smallest, which avoids the issue of taking the \(\min\). Consider \(dp[i][j][k]\) as having chosen up to the \(i\)-th number, with \(j\) numbers pending and \(k\) single pairs pending. For the transitions, we can try a case analysis. If this number is one of some single pair, then one option is to do nothing at all, and the other is to try matching it, \(j -= 1\). If it is not one of a single pair, then either match it or leave it hanging.
Continue reading →Chinese original · English translation by Claude Opus 5.5
Fairly obviously, we need to pick two point sets, and the final contribution is the product of the two sets’ ranges. Sort them, and then just go through every interval of length \(n\).
Continue reading →Chinese original · English translation by Claude Opus 5.5
It’s still a bit of a pain to write; LCT + offline processing put together is fairly hard to code.
First, we can consider going offline, so that we can think about the problem color by color. Suppose we are now at color \(c\), so we need to count, for each moment, the number of paths that do not contain this color, and take differences (that is, do it for each moment). Now the colors are only black and white, so we just need to make the vertices of this color white, and then count the square of the size of each connected component of black vertices.
Continue reading →Chinese original · English translation by Claude Opus 5.5