0% found this document useful (0 votes)
4 views2 pages

Translated Document Bdoi24

The document outlines various algorithms and approaches for problems related to hats, spanning trees, removals, and databases. It describes methods for managing segments of values, coloring trees, dynamic programming transitions, and using a scanline approach with Fenwick trees. Each section includes complexity analysis and specific conditions for transitions or calculations.

Uploaded by

iamirk13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Translated Document Bdoi24

The document outlines various algorithms and approaches for problems related to hats, spanning trees, removals, and databases. It describes methods for managing segments of values, coloring trees, dynamic programming transitions, and using a scanline approach with Fenwick trees. Each section includes complexity analysis and specific conditions for transitions or calculations.

Uploaded by

iamirk13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

0.1 B.

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

Initially, only k = 0 is available.


- If si = 1, we need to check the position p of number i. If we could have used exactly the segment up to p, then now we can use
- If si = 0, we need to check the maximum number of hats we could have used so far. If the number of the next hat does not mat

0.2 C. Pepeland

Note that an answer always exists.


We will choose some spanning tree and suspend it from some vertex.

- 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.

- We can remove ai if and only if j < k and i - j <= p.


- If we can remove ai, then there is a transition from dp(i, j) to dp(i+1, j+1) at cost 0.

The answer is the maximum dp(n, j) over all 0 <= j <= k.

This results in a solution with complexity O(nm).

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.

This results in a solution with complexity O((n+q) log(n+q)).

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.

- Let u be the number formed by the found bits.


- Let f be the Fenwick tree in which we search for a minimal prefix with a sufficiently large sum.
- Let w be the remaining sum to collect (i.e., the difference between the initial w and the sum on the prefix [0; u)).

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.

By repeating this for all b, we obtain the final answer.

You might also like