When solving a counting problem, if you run into a condition requiring \(x \bmod m = 0\), and the formula is expensive to compute but contains binomial coefficients, you can consider using the roots of unity filter.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First time doing this type of problem. Badass, badass (fist-palm salute).
First consider how to compute the denominator: if \(f_i\) is the number of distinct trees of size \(i\), then we obviously get \(f_i = \sum_{j = 0}^{n - 1} f_j f_{n - j - 1}\). Having got this far, divide-and-conquer FFT? No, the data range reaches an astonishing \(10^9\), so divide-and-conquer FFT is obviously impractical. We can keep deriving:
Continue reading →Chinese original · English translation by Claude Opus 5.5
Following the doubling idea from polynomial inversion, we can write a derivation like this: suppose we already know that, under \(\pmod {x^{\lceil \frac{n}{2} \rceil}}\), we have found \(B'(x)\) as the current solution, and now we want to step up to \(\pmod x^n\). Then we can write
Continue reading →Chinese original · English translation by Claude Opus 5.5
No matter how safe you feel, once the contest is over you’ll still have lost points, and you’ll find that a slight tweak can fucking add dozens of points. That’s life.
kal0rona
Continue reading →Chinese original · English translation by Claude Opus 5.5
Since it's a permutation, while reading the input we can place the values seen so far on a number line, and we find that a single symmetric pair is enough. We can use the idea of hashing to heavily mod a Fenwick tree, maintain the hashes of the string and of the reversed string, and then just compare them.
Continue reading →Chinese original · English translation by Claude Opus 5.5