· Olympiad in Informatics

Extended Min-Max Inversion

First, you need to learn min-max inversion and binomial inversion. The formulas are as follows:

\[\begin{gathered} \max(S) = \sum_{T \subset S} (-1)^{|T| - 1} \min(T) \\ f_i = \sum_{j = 0}^i {i \choose j} g_j \Leftrightarrow g_i = \sum_{j = 0}^i (-1)^{i - j} {i \choose j} f_j \end{gathered}\]

Then, you need a certain understanding of inversion and inclusion–exclusion, enough to understand what the inclusion–exclusion coefficients mean.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

Fast Walsh Transform | FWT

Memorize the formulas:

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

P3346: [ZJOI2015] Gensokyo Blessed by the Gods — Solution

This counts as a general application of the generalized suffix automaton. We can do this the same way as counting over multiple strings, except that while running the DFS on the tree we need to record the SAM node at each branching point, and then backtrack. The rest, the method for counting distinct substrings, is a very standard trick.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

P3704: [SDOI2017] Number Table — Solution

First, write out the expression for the answer:

\[\prod_{i = 1}^n \prod_{i = 1}^m f(\gcd(i, j))\]

Same old standard trick: enumerate the common divisor:

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

P5221: Product — Solution

First, let's do the usual standard trick and turn the enumerated term into \(\gcd\).

\[\begin{aligned} \prod_{i = 1}^n \prod_{j = 1}^n \frac{lcm(i, j)}{gcd(i, j)} &= \prod_{i = 1}^n \prod_{j = 1}^n \frac{ij}{gcd(i, j)^2} \\ &= \prod_{d = 1}^n d^{\sum_{i = 1}^n \sum_{j = 1}^n [\gcd(i, j) = d]} \end{aligned}\]

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

Codeforces Round #609 (Div. 1) - Problem-Solving Report

Take the first \(k\) digits as the repeating block, and compare it against each following block of length \(k\); if the first block is smaller, just add one to it.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

AtCoder Grand Contest 002E - Leftmost Ball — Solution

We notice that we only need to make sure that at any moment the number of \(0\)s is greater than or equal to the number of colors. Directly considering stuffing the balls in one by one means dealing not only with the issue of identical balls but also with the concrete arrangement of colors, which is a real pain, so instead let's place all the balls on the sequence in one go: let \(dp[i][j]\) be the state with \(i\) \(0\)s and \(j\) colors, and we can transition like this:

\[dp[i][j] = dp[i - 1][j] + {n - i + (n - j + 1) \times (k - 2) - 1 \choose k - 2 } dp[i][j - 1] (n - j + 1)\]

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

AtCoder Grand Contest 001E - BBQ Hard — Solution

This is also a rather clever transformation idea.

Let's write out the expression:

\[\sum_{i = 1}^n \sum_{j = i + 1}^n {a_i + b_i + a_j + b_j \choose a_i + b_i}\]

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

UOJ#275: [Tsinghua Training Camp 2016] Binomial Coefficient Problem — Solution

So goddamn godlike.

Consider using Lucas to decompose the binomial coefficient:

\[{n \choose m} = {n / k \choose m / k} {n \mod k \choose m \mod k}\]

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

Suffix Automaton | SAM

The suffix automaton is a powerful tool for handling string information. A suffix automaton is stored on a trie, and together with the Link pointers it can be regarded as a DAG. Any path starting from the origin can be regarded as a substring of the string, and no duplicate substring information exists on a suffix automaton (however, we can make some extensions to maintain substring position information).

Continue reading →Chinese original · English translation by Claude Opus 5.5