First, notice that \(k\) is really small and \(n\) is fairly small too, so consider just brute force: enumerate the order in which the supermarkets are visited, then chain them together and that's it (just precompute \(k\) runs of shortest paths beforehand).
Continue reading →Chinese original · English translation by Claude Opus 5.5
The whole approach can be turned into 2D point counting under CDQ divide and conquer. The \(x\) axis is the axis of ordinary physical distance, and then the \(y\) axis is the axis of signal reception; just split a query apart into inclusion–exclusion form.
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem is so interesting! It reminds me to always keep this threshold + \(0/1\) conversion trick in mind, no matter what.
We can first binary search for the value at position \(c\), then turn every value greater than or equal to \(c\) into \(1\) and every smaller one into \(0\). Then, when sorting, we find that it is really just rearranging where the zeros and ones are, so a segment tree with range updates gets it done. Finally, check whether position \(c\) is \(0/1\) to decide whether to keep binary searching.
Continue reading →Chinese original · English translation by Claude Opus 5.5
This whole set is the brute force works miracles series.
We enumerate one endpoint, then check whether, with this point as the right endpoint, it counts toward the answer. We take the prefix sums \(prefix[]\) of the sequence, and then find that it counts toward the answer if and only if \(prefix[i - n]\) is less than or equal to the minimum over \([i - n + 1, i]\). This guarantees that all the prefixes are non-negative.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First, when there are \(k\) leaves, the whole complete binary tree has \(2k - 1\) nodes. We set up a DP to do the counting.
Consider defining the state \(dp[i][j]\) as: the current tree already has \(i\) nodes, and the path from the currently added node to the root has length \(j\) units. Consider the following transitions:
At first I thought it was about picking \(\log n\) base points and then doing stuff on the bidirectional edges, but in the end I found that finding the minimum cycle in the graph has a very high complexity. So, GG.
The intended solution considers shrinking the size of the problem: that is, handling some answers as special cases in advance. For example, if more than three points are connected on some bit, then the size of the cycle can be determined to be \(3\), which is the smallest possible. Consider that once there are more than \(3 \times 60\) of them, we can directly conclude that the answer is \(3\).
Continue reading →Chinese original · English translation by Claude Opus 5.5
We can just do a brute-force DP: let the state \(dp[i][j]\) be the answer for \(i\) copies of \(1\) and \(j\) copies of \(-1\). Then we can transition from the case with one fewer \(1\) and the case with one fewer \(-1\):
For the case with one fewer \(1\), that is, \(dp[i - 1][j]\), we put the \(1\) at the front of such sequences, which adds one to the maximum prefix sum of every sequence, so the contribution is \(dp[i - 1][j] + {i + j - 1 \choose j}\).
For the case with one fewer \(-1\), that is, \(dp[i][j - 1]\), we put the \(-1\) at the front of such intervals, and two cases arise: for sequences whose contribution is greater than \(0\), the contribution of the \(-1\) is the number of such sequences; if the contribution was already less than or equal to \(0\), then there is no contribution. So we also need to separately count the number of sequences with no contribution and add it back.
Continue reading →Chinese original · English translation by Claude Opus 5.5
You have to think it through; you can't just take things for granted. That one's addressed to me.
Connect the connected components with edges and count each BFS expansion as one click, then determine the path lengths in \(O(n^2)\), and finally just decide by parity.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First, compute it indirectly. The initial answer is \(n!\), and then we consider removing, by inclusion–exclusion, the arrangements that follow the sorting rule. It turns out we can consider them separately, in inclusion–exclusion order: first consider the ones counted on only the first dimension and only the second dimension, then add back the ones that consider both dimensions.
The method for the first and the second dimension is very obvious: after sorting, just use permutations of a multiset, multiplying things together inside each range of equal values. If there are \(k\) consecutive runs, then this part of the answer is \(\prod_{i = 1}^l len_k!\).
Continue reading →Chinese original · English translation by Claude Opus 5.5