A. Iridescent Universe 2
First, we can perform a binary search on . Now, the surface of the sphere is divided into several regions by the line segments formed by the flights. We now only need to check whether there exists a point contained in at most regions.
Without loss of generality, let this point be taken at the intersection of the boundaries of two regions. Thus, one can enumerate one region, find all intersections of its boundary with the boundaries of other regions, and then count the number of regions containing each intersection point.
In addition, the time complexity can be optimized by randomly shuffling the order of processing the regions.
B. Queue Editor
C. Adjacent Add
The problem is equivalent to determining a sequence such that are all equal, and can be nonzero only for positions . If the final equal value is already determined, then the sequence can be directly computed recursively, i.e. . The problem is transformed into checking whether there exists a such that the computed .
The expression of in terms of can be written as , but direct computation gives very large numbers. However, note that the absolute value of cannot be too large. For a given , the recursive process can be simulated in time complexity to decide validity. Several approaches are available for the remaining part of the problem:
- Perform a binary search on , and each time compare the computed with (since only the sign matters, the result can be returned immediately if is sufficiently large or small), with time complexity .
- Use high-precision arithmetic to compute approximately the first terms, or use floating-point operations to store very large numbers for estimating the value of , or select a large prime number and compute the exact value of in a modulo field, followed by verification. The time complexity of this algorithm is .
D. Circular Matching
E. Circular Convolution 2
This problem is equivalent to, for each , choosing such that , and maximizing .
After sorting , first greedily pick the minimum value times, which yields the answer for . Subtracting the minimum value from the other elements of transforms them into items with volume and value, where the number of items that can be chosen is arbitrary (since choosing more than items is clearly not optimal). When adding an item, only one update like in a congruence shortest-path algorithm is required, with time complexity .
By traversing the items from smallest to largest, if transferring from can no longer update the answer, then this item can be replaced by previously added items without being worse, so it can be skipped. In the test data of this problem, about only items need to be actually added, which is acceptable.
F. Even Circuit
Consider enumerating even from small to large, and check whether it is feasible. One only needs to enumerate all choices of , and if two choices have the same XOR sum, then there must exist a set of size whose XOR sum is . Therefore, the actual amount of search does not exceed the value range. When the total number of choices exceeds the value range, a solution always exists. Thus, the actual number of values that need to be searched is very small, which is acceptable.
G. Master of Cards
First, handle the case where each card has exactly two attributes. Construct a graph with vertices and edges, where each vertex represents a value of an attribute, and each edge connecting two vertices represents the two attributes of a card. Two cards can be paired if and only if their corresponding edges share a common vertex.
The minimum number of unpairable edges is the number of connected components with an odd number of edges. The construction is as follows: for each connected component, find its spanning tree. For each forward edge, attach it at its ancestor. For each node, if there is an unpaired edge in a child’s subtree, pair it with the edge connecting to that child; then greedily pair the edges going out from this node. It is easy to see that with this construction, each subtree always leaves at most one edge.
Next consider the case with three attributes. It is easy to see that by removing one attribute from each card, i.e., when the three cards become , , , the number of connected components with an odd number of edges is always minimized. A similar solution can then be used to solve the problem.
The time complexity is .
H. Shortcut on Tree
This problem always has a solution. The following construction ensures that for each node , the shortest distances from to and from to are both at most .
For each node , connect an edge between it and , either or . Then for each node :
- If edge is chosen, then there must exist a child node of such that is chosen;
- If edge is chosen, then the parent node of must choose .
Thus, simply perform a DFS of the whole tree: for each node , if there exists a child node choosing , then choose , otherwise choose .
The time complexity is .
I. Ethanol
J. International Olympiad in Fishing
K. Degree Sequence 3
L. Bot Friends 2
M. Traveling in Cells 3
Let’s just assume that . The minimum cost between two points is clearly achieved by first moving to the nearest two points congruent to the destination’s coordinate modulo , and then jumping to the destination. Thus, we consider partitioning the number axis into blocks of length .
It can be easily proven by the adjustment method: the optimal destination must lie in the block containing the median or the two adjacent blocks. By enumerating these blocks, the problem reduces to selecting a point within a block such that the total minimum cost for moving the points to this point is minimized.
Suppose we are considering points in the block as potential destinations. For each given point among the points, we analyze its contribution. The current block is divided at into two parts. The left part will only choose to move to either or , while the right part will only choose to move to either or . For both parts, it is easy to determine the breakpoint between choosing the left or right option. Thus, the contribution of each given point can be described by piecewise linear functions.
Finally, we only need to process the obtained linear functions offline by sorting the breakpoints and handling them efficiently.
The time complexity is .