Translated Document Bdoi24
Translated Document Bdoi24
Hats
We will iterate over i in [0; n) and maintain a segment of values k such that we could have used exactly k hats up to this momen
0.2 C. Pepeland
- We color the root with a color that is not used by any edge.
- Then, we color the vertices in the order of a DFS traversal.
Let vertex u have a parent p in the tree, and let the edge between them have color c.
- If the color of p is c, we paint u with any other color.
- Otherwise, we paint u with color c.
0.3 D. Removals
Let dp(i, j) be the answer for the prefix of length i if we have removed exactly j numbers.
For all 0 <= i < n, we can always transition from dp(i, j) to dp(i+1, j) at cost ai.
Let p be the index of the closest position to the left of i that exists in b, if such a position exists, or −infinity if not.
0.4 E. Databases
We will use a scanline approach over i in [0; n) while maintaining the queries that have been applied at the current position i.
- Specifically, we will reverse the query indices and maintain a Fenwick tree on [0; q) with ones for active queries and zeros for t
- Additionally, for each value, we will maintain a set of active queries that added this value, along with another Fenwick tree on [
To find the number of distinct elements in the i-th queue at the end, we need to:
1. Find the minimum prefix in the first Fenwick tree with a sum >= ci.
2. Compute the sum of this prefix in the second Fenwick tree.
P.S.
We describe separately how to find the minimum prefix in the Fenwick tree with a sum >= w (returning q if none exists).
Here, we use the Fenwick tree implementation with 0-based indexing, where node i corresponds to the range [i & (i+1), i].
We reconstruct the answer bit by bit from the most significant to the least significant.
If u + 2^b - 1 < q and f[u + 2^b - 1] < w, then the answer is at least u + 2^b, meaning that bit b is definitely 1. We then add this bi
Otherwise, the answer is less than u + 2^b, meaning that bit b is definitely 0.