· Olympiad in Informatics

The Top-k Solutions Problem for 0/1 Knapsack

I've recently been getting ready to start reviewing knapsack problems, and right before reading Nine Lectures on Knapsack I happened to land on this problem at random, so here's a simple summary.

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

· Olympiad in Informatics

[Universal OJ Round #3] Fusion Reaction Strength — Solution

Pretty easy to come up with. Consider brute force: after computing the \(\gcd\) of the two, enumerate the largest factor, and that is the answer. So how do we speed it up? We notice that the largest factor of \(gcd\) must also be one of the factors of \(a_1\), so we just precompute the factors of \(a_i\), and then when answering queries we directly enumerate in \(\log n\).

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

· Olympiad in Informatics

[POI2014] MRO-Ant colony — Solution

If you understand the problem statement correctly, it is not hard to think of using an \(O(n)\) DFS to find the lower and upper bounds of every leaf node (and then I stopped thinking). Just binary search the two endpoints of each range to get the total length.

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

· Olympiad in Informatics

Small-to-Large Merging on Trees | DSU on tree

The structure of a tree makes some data hard to merge directly and quickly, and so we have small-to-large merging on trees, a magical way of optimizing a merge that takes \(O(n)\) time down to \(O(\log n)\). If you have studied heavy-light decomposition before, then learning small-to-large merging on trees is very easy.

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

· Olympiad in Informatics

Codeforces 1239A: Ivan the Fool and the Probability Theory — Solution

First, we need one property: once the first row and the first column are fixed, the whole configuration is completely determined. This can be proved by induction:

Proof If the colors of cells \((i - 1, j)\), \((i, j - 1)\) and \((i - 1, j - 1)\) are fixed, then clearly the color of \((i, j)\) is uniquely determined. If the first row and the first column can be fixed, then by the above, a unique configuration is generated.

So to count the configurations, we need to count the valid ways to fill the first row and the first column. This turns the problem into one on a strip.

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

· Olympiad in Informatics

[Miscellaneous Problems] - October 16, 2019

In the end it turned out to be just a big sqrt-decomposition brute force; it would be nice if there were a more interesting solution (though this information has no good way to be merged in the first place; then again, some kind of two-dimensional online partial-order structure could actually solve this problem).

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

· Things

Interim Summary: Mid-October

I forgot to write September's summary, and then put it off until now, so I might as well just rename it an interim summary.

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

· Olympiad in Informatics

Codeforces 1174D: Ehab and the Expected XOR Problem — Solution

This problem is pretty neat, and I worked it out on my own fairly smoothly.

Consider setting up prefix XOR sums \(\{ S_i \}\). By the property that XOR works bit by bit, clearly every \(S_i\) will be less than \(2^n\). Finally, we can turn the constraints into:

  • No two prefix sums are equal.
  • No pair of prefix sums has an XOR value of \(x\).

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

· Olympiad in Informatics

[NOIp 2012 Epidemic Control] Solution

You can probably come up with binary searching on the time, then making every node jump upward, and then allocating the nodes that can be assigned across subtrees. That's pretty much the idea, and it's quite a natural one.

But there are some details worth noting: the priority between cross-subtree allocation and covering the current subtree has to be handled properly. If you don't handle this right, you'll only pass 80% of the data on Luogu. I spent a long time fixing this part, and in the end found that you need to make cross-subtree allocation the first enumeration, and then, in between, do a second enumeration over the subtrees' coverage needs (put them in a heap and pair them greedily).

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

· Olympiad in Informatics

[Nowcoder OI Weekly Contest 2 - Senior Division] Problem-Solving Report

I basically just messed around: operate from the outermost layer inward, count the operations, take the remainder, and map it to the corresponding name. I don't really understand why it passed.

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