The main approach to this problem is greedy. We enumerate \(i\) from \(n-1\) down to \(1\). Let \(vis[i]\) denote whether the node numbered \(i\) can be transferred, and \(arr[i]\) the number at position \(i\); in the set of transfer relations, we look for \((i,j), vis[j]=true\) and find those \(j\). Since we transfer from back to front, the positions of the \(j\) we find are all after \(i\), which meets the transfer requirement. Then we check whether the answer transferred so far \(ans\), the number of relations satisfying the condition \(cnt\), and \(i\) sum to \(n\). If they do, that means the transfer meets the condition, and we perform the transfer directly; if not, we put the mark on this node, meaning it can be transferred from now on.
Continue reading →Chinese original · English translation by Claude Opus 5.5
Let’s first consider the unrestricted version, that is, ignoring the coin-count limits in the queries. We can just hack at it with an unbounded knapsack, and the complexity is linear.
Continue reading →Chinese original · English translation by Claude Opus 5.5
The prerequisites for learning difference on trees are:
Lowest common ancestor (LCA)
Linear difference arrays
Once you have learned these, we can start learning difference on trees. The idea behind difference on trees is similar to difference arrays: when we have no choice but to take prefix sums, turn range operations into single-point operations to lower the complexity. Difference on trees has appeared twice in NOIp-series contests, so it is well worth learning (I suspect the problem setters didn't dare set heavy-light decomposition, but still wanted to test how familiar contestants are with operations on trees, so they went with this cheap trick of a thing). Let's first learn a basic operation: vertex range add on a path.
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem is still fairly interesting (ugh, I had to read the solution for ages before I could write it, I’m so weak). The main thing is turning \(d\) into:
You can get a hand-wavy intuition for it: every time a divisor is enumerated, it is counted only when the two are coprime, which avoids counting anything twice.
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem is still pretty interesting; the way the graph is built is really clever. First, we solve the DP for the first question in \(O(n \log n)\) time, and along the way get an array \(f[i]\), meaning the length of the longest subsequence ending at \(i\). When building the graph, note that the vertex for each position has to be split into two: this is to keep the answer unique. So whenever \(f[i]=1\) for vertex \(i\), add the edge \((s,i)\); whenever \(f[i]=k\) for vertex \(i\), add the edge \((i+n,t)\). After that, if we add edges for \((u,v), f[v] = f[u] + 1, arr[u] \leq arr[v]\), just run a max flow and the answer comes out.
Continue reading →Chinese original · English translation by Claude Opus 5.5
It's been a long time since I wrote a blog post; I've been busy with regular classes lately, so I haven't updated the blog. This month went pretty well. I studied regular classes for a long time, got crushed in every way by the big shots in my class, and in the end my monthly exam just flat-out blew up. That's a fairly ordinary thing, I suppose. The Lüyin Cup football matches were pretty fun, and the gods in my class played really well.
Continue reading →Chinese original · English translation by Claude Opus 5.5
I've been back for over a week now, and everything has gone pretty smoothly (especially getting out of the winter break homework), except that I came down with a fever over the weekend, and my throat still really hurts. These are all just little episodes, nothing serious.
Continue reading →Chinese original · English translation by Claude Opus 5.5