· Olympiad in Informatics

HNOI 2018 Provincial Team Training Day 1 - Problem-Solving Report

At first glance this problem seems to need a Link Cut Tree, but it doesn’t: if we still treat node \(1\) as the root to process the subtree information and put it into a segment tree, then for the later queries we only need some flexible case analysis. When the real root is \(root\), for \(u, v\), their \(LCA\) is obviously the deepest of \(lca(u, v), lca(root, u), lca(root, v)\). As for modifying and querying weights, we only need to discuss the two ancestor relationships and the parallel relationship.

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

· Olympiad in Informatics

QuestOJ 2018 - Girls — Solution

Just do an inclusion–exclusion; the answer equals:

\[f_0 - f_1 + f_2 - f_3\]

where \(f_i\) stands for at least \(i\) conflicting pairs on the cycle. They are computed as follows:

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

· Olympiad in Informatics

Cartesian Tree

The values in a node's subtree are all smaller than the node itself (the heap property), and the whole subtree is a contiguous substring of the sequence.

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

· Olympiad in Informatics

Codeforces 981H: K Paths — Solution

First, carefully dissect what the problem actually means: we need to fix a path that has to be passed through \(k\) times, and then extend no more than \(k\) branches from the two ends of the path, with each branch having a subtree all to itself, and count the number of ways.

So we can first fix \(1\) as the root, then compute, with point \(u\) as an endpoint and the branches inside its subtree, the number of ways \(f_u\), then compute the number of ways \(g_u\) toward the parent's side, and then enumerate \((u, v)\):

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

· Olympiad in Informatics

BZOJ3527: [ZJOI2014] Force

First, we know:

\[E_i = \sum_{j = 1}^{i - 1}\frac{q_j}{(i - j)^2} - \sum_{j = i + 1}^{n}\frac{q_j}{(i - j)^2}\]

Now we need all of them. We can consider splitting it into a front part and a back part and computing them separately. First consider the front part:

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

· Olympiad in Informatics

[Miscellaneous Problems] - December 9, 2019

Lately I've been learning some tech and doing some template problems. Now I'll gather a few problems I personally think are fairly good as the first miscellaneous problem set of December.

First, let's consider the case of odd-length segments (\(\{a_n\}\) is already sorted): fix the median as \(a_{mid}\), and we find that the answer is (the sum of everything on the left minus the median) plus (the sum of everything on the right minus the median), divided by the number of elements. To maximize the value, the right side obviously has to be chosen close to the right endpoint, while the left side has to be chosen close to the median. At this point we can consider using binary search on the answer to optimize: it cuts down the complexity of enumerating the length.

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

· Olympiad in Informatics

AC Automaton | Aho-Corasick Automaton

The Aho–Corasick automaton is a finite-state automaton, commonly used for string matching with multiple patterns.

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

· Olympiad in Informatics

CSP-S2 Jiangxi Retake: A Brief Summary

For the two days after the nationwide second round ended, I was frantically catching up on regular classes. At noon on Tuesday, I went back to class, sneaked a look at my phone, and found a pile of missed calls. By the time I opened WeChat, I could already see people complaining about Jiangxi Province holding the exam again.

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

· Things

CSP-S2 Diary & Summary

Spent the whole morning reading and reviewing, then watched the coach and the younger students kick a bottle around the classroom (goofy stuff). I felt I was in decent shape. In the afternoon we all went over the things to watch out for and such, and then lcx and I headed off to NCU.

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

· Olympiad in Informatics

P2125: Books on the Library Shelf — Solution

This problem is a good one for mathematical reasoning.

We consider treating every move as a one-way move, and let \(x_i\) be the number of books moved from \(i\) to \(i - 1\). Obviously, if we want to move books to the right, we just subtract the corresponding amount from \(x_{i + 1}\).

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