Since I am weak at divide and conquer, I came to grind divide-and-conquer problems.
First, think about the 50-point \(O(n^2)\) approach. Record each position's original value, its maximum value after changes, and its minimum value after changes. Then you find that a position \(i\) contributes to a later position \(j\) if and only if:
This problem was truly suffocating, and it also taught me that going on QQ during a contest is a very bad habit.
The 60-point solution to this problem is extremely obvious: group items of the same volume into one item, whose value is the largest value among that volume. This squeezes the number of items down to under 100.
But this can't get the full score, and the capacity for the full score is enormous, so the usual DP optimizations won't work. After doing the compression above, we can consider some greedy optimization. Next I'll introduce this greedy strategy in detail:
Continue reading →Chinese original · English translation by Claude Opus 5.5
LCT (Link Cut Tree) is a flexible data structure for maintaining tree paths. Unlike a segment tree, an LCT usually uses Splay, a very elegant and flexible data structure, to maintain the tree paths. Because an LCT supports adding and deleting edges dynamically, many problems can be solved by breaking through some of their restrictions.
Continue reading →Chinese original · English translation by Claude Opus 5.5
Simply put, the problem asks: given the condition \(\{x_i \mod m \in [1, m - 1]\}\), count the \(k\)-tuples that meet it. We can first take every \(x_i\) modulo \(m\), then let \(A = \sum_{i = 1}^k (x_i \mod m)\) (note: \(A\) is not taken modulo as a whole, it is just the sum of the individual remainders). We know that \(A \mod m = n \mod m\), and the upper bound of \(A\) is \(A = k(m - 1)\) (the upper bound of each term).
After this setup, the problem can be turned into: for each distinct \(A\), with \(A \mod m = n \mod m\) and \(A = \sum_{i = 1}^k (x_i \mod m), \forall i, x_i \in [1, m - 1]\) holding, how many ways there are to form the \(k\)-tuples. First, we can enumerate each \(A\) to narrow down the problem. Based on the conditions \(A\) satisfies, we can iterate over \(i\) like this to get every \(A\):
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem is pretty good. It showed me that segment trees can pull off moves like this.
Consider a segment tree that maintains, for a range, the shortest paths from the row entrances to the row exits; the way it is maintained is, roughly, a lot like Floyd. There’s not much to say, just read the code.
Continue reading →Chinese original · English translation by Claude Opus 5.5
For this problem, the quadratic-function brute force is worth 60 points; the intended solution comes from a paper.
This problem mainly uses a conclusion, and applies an idea from the Euclidean algorithm to simplify the problem. First, we adjust the vectors to the same direction, and make \(|\vec{a}| < |\vec{b}|\), and then we derive a conclusion:
Conclusion For \(\vec{a}, \vec{b}\), if \(<\vec{a}, \vec{b}> \geq \frac{\pi}{3}\), then the answer is \(min\{|\vec{a}|, |\vec{b}|\}\).
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem's formula is the same as the one in an F problem on Codeforces, which made me think it was BSGS or some such thing, but in the end it turned out to really be a matrix multiplication problem.
Consider that any answer is made up of a product of powers of \(\{f_n\}\). Since \(k\) is small, we can consider computing the exponent of each \(f\), and then we can use fast exponentiation to compute these things.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First, in this problem probability and expectation are computed separately, and the DP is really a DP over probabilities. Consider splitting by bits: let \(dp_b [u]\) be the probability that, going from \(u \to n\), bit \(b\) is \(1\). Then clearly: