跳到正文

题解

The 3rd Universal Cup Semifinals Tutorials

Milmon约 14 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年6月8日
篇幅
约 14 分钟

版本

  1. v1当前

A. Iridescent Universe 2

First, we can perform a binary search on dd. Now, the surface of the sphere is divided into several regions by the nn line segments formed by the nn flights. We now only need to check whether there exists a point contained in at most kk 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 nn regions.

B. Queue Editor

C. Adjacent Add

The problem is equivalent to determining a sequence xx such that ai+xi+kxi−1a_i + x_i + kx_{i - 1} are all equal, and xx can be nonzero only for positions 1∼n−11 \sim n - 1. If the final equal value vv is already determined, then the sequence xx can be directly computed recursively, i.e. xi=v−(ai+kxi−1)x_i = v - (a_i + kx_{i - 1}). The problem is transformed into checking whether there exists a vv such that the computed xn=0x_n = 0.

The expression of xnx_n in terms of vv can be written as xn=Kv+Bx_n = Kv + B, but direct computation gives very large numbers. However, note that the absolute value of vv cannot be too large. For a given vv, the recursive process can be simulated in O(n)\mathcal{O}(n) time complexity to decide validity. Several approaches are available for the remaining part of the problem:

  • Perform a binary search on vv, and each time compare the computed xnx_n with 00 (since only the sign matters, the result can be returned immediately if xx is sufficiently large or small), with time complexity O(nlog⁡a)\mathcal{O}(n \log a).
  • Use high-precision arithmetic to compute approximately the first 100100 terms, or use floating-point operations to store very large numbers for estimating the value of vv, or select a large prime number and compute the exact value of vv in a modulo field, followed by verification. The time complexity of this algorithm is O(n)\mathcal{O}(n).

D. Circular Matching

E. Circular Convolution 2

This problem is equivalent to, for each 0≤p<n0 \leq p < n, choosing 0≤x1,x2,⋯ ,xn<n0 \leq x_1, x_2, \cdots, x_n < n such that ∑xi≡p(modn)\sum x_i \equiv p \pmod n, and maximizing ∑axi\sum a_{x_i}.

After sorting aia_i, first greedily pick the minimum value nn times, which yields the answer for p=0p = 0. Subtracting the minimum value from the other elements of aa transforms them into items with volume and value, where the number of items that can be chosen is arbitrary (since choosing more than nn items is clearly not optimal). When adding an item, only one update like in a congruence shortest-path algorithm is required, with time complexity O(n)\mathcal{O}(n).

By traversing the items from smallest to largest, if transferring from 00 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 8080 items need to be actually added, which is acceptable.

F. Even Circuit

Consider enumerating even kk from small to large, and check whether it is feasible. One only needs to enumerate all choices of 12k\frac{1}{2} k, and if two choices have the same XOR sum, then there must exist a set of size ≤k\leq k whose XOR sum is 00. Therefore, the actual amount of search does not exceed the value range. When the total number of choices (n12k)\dbinom{n}{\frac{1}{2} k} exceeds the value range, a solution always exists. Thus, the actual number of kk 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 2n2n vertices and nn 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 (ai,bi,∗)(a_i, b_i, *), (ai,∗,ci)(a_i, *, c_i), (∗,bi,ci)(*, b_i, c_i), 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 O(n)\mathcal{O}(n).

H. Shortcut on Tree

This problem always has a solution. The following construction ensures that for each node ii, the shortest distances from ii to 11 and from 11 to ii are both at most 22.

For each node i≠1i \neq 1, connect an edge between it and 11, either 1→i1 \to i or i→1i \to 1. Then for each node i≠1i \neq 1:

  • If edge 1→i1 \to i is chosen, then there must exist a child node xx of ii such that x→1x \to 1 is chosen;
  • If edge i→1i \to 1 is chosen, then the parent node xx of ii must choose 1→i1 \to i.

Thus, simply perform a DFS of the whole tree: for each node i≠1i \neq 1, if there exists a child node xx choosing x→1x \to 1, then choose 1→i1 \to i, otherwise choose i→1i \to 1.

The time complexity is O(n)\mathcal{O}(n).

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 b≤ab \leq a. The minimum cost between two points is clearly achieved by first moving to the nearest two points congruent to the destination’s coordinate modulo aa, and then jumping to the destination. Thus, we consider partitioning the number axis into blocks of length aa.

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 nn points to this point is minimized.

Suppose we are considering points in the block [L,L+a][L, L + a] as potential destinations. For each given point xix_i among the nn points, we analyze its contribution. The current block is divided at r=xi mod ar = x_i \bmod a into two parts. The left part will only choose to move to either L+rL + r or L+r−aL + r - a, while the right part will only choose to move to either L+rL + r or L+r+aL + r + a. 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 O(1)\mathcal{O}(1) piecewise linear functions.

Finally, we only need to process the obtained O(n)\mathcal{O}(n) linear functions offline by sorting the breakpoints and handling them efficiently.

The time complexity is O(nlog⁡n)\mathcal{O}(n \log n).

原文
存档评论1 条抓取于