跳到正文

个人记录

ICPC Asia Shenyang Regional Contest 2022 Solutions

Otomachi_Una_约 22 分钟
原文
文章信息与版本

文章信息

发布
2023年12月20日
收录
2026年8月22日
更新
2026年11月18日
篇幅
约 22 分钟
获赞
1

版本

  1. v1当前

A. Absolute Difference

  • Difficulty factor: 55.
  • Quality factor: 44.

Discrete Difference Case:

  • If a,ba,b are in different segments, it can be calculated directly.
  • If a,ba,b are in the same segment, the expectation is segment length3\dfrac{\text{segment length}}{3}.

Time complexity: O(nlog⁡n)\mathcal O(n\log n).

B. Binary Substrings

  • Difficulty factor: 88.
  • Quality factor: 77.

First, for a binary string of length kk, SS contains at most min⁡(2k,n−k+1)\min(2^k,n-k+1) distinct strings. Intuition tells us to take equality here.

Consider first that if there exists an integer kk satisfying n=2k+k−1n=2^k+k-1, then our task is to make two of the nn 01\tt 01 strings of length kk different, such that the sequence is the de Bruijn\text{de Bruijn} sequence. The construction method is to construct a graph of 2k−12^{k-1} points, and for a 01\tt 01 string of length 2k2^k, connect the edges of the two points represented by the first k−1k-1 string and the second k−1k-1 string. Then the de Bruijn\text{de Bruijn} sequence is essentially the Euler loop of this graph. It’s straightforward to run.

Now consider 2k+k−1≤n<2k+1+k2^k+k-1\leq n<2^{k+1}+k. We first construct a de Bruijn\text{de Bruijn} sequence of length 2k+k−12^k+k-1. Then that graph of 2k2^k points is actually a Hamiltonian path of the graph of 2k+12^{k+1}, denoted u1,u2,…,u2ku_1,u_2,\dots,u_{2^k}. Now that ui→ui+1u_i\to u_{i+1} has been given a concatenation of edges, we give another concatenation of edges to (ui XOR 2k)→(ui+1 XOR 1)(u_i\text{ XOR }2^k)\to (u_{i+1}\text{ XOR }1), and it’s easy to show that none of these dots will be present in uiu_i.

Now we have what amounts to a Hamiltonian path on the graph of 2k+12^{k+1}, and then also divide the remaining edges also into rings. We just need to greedily add rings to this path.

Time complexity: O(n)\mathcal O(n).

C. Clamped Sequence

  • Difficulty factor: 11.
  • Quality factor: 33.

r−lr-l must be dd, and the only available ll are ai,ai−da_i,a_i-d, O(n)\mathcal O(n). Direct violent enumeration is sufficient.

Time complexity: O(n2)\mathcal O(n^2).

D. DRX vs. T1

  • Difficulty factor: 0.50.5.
  • Quality factor: 11.

Introductory question.

Time Complexity: O(1)\mathcal O(1).

E. Graph Completing

  • Difficulty factor: 66.
  • Quality factor: 77.

Consider shrinking the point first, then consider the contribution made by an extra edge (u,v)(u,v):

  • If u,vu,v is inside a scc\text{scc} to begin with. If u,vu,v is within a scc\text{scc} to begin with, then there is no contribution.
  • If u,vu,v is not within a scc\text{scc}, then this edge overwrites the edge between sccu,sccvscc_u,scc_v in the contraction tree.

The final graph is connected if and only if every edge is covered.

We only need to care about the shrinking tree. Every edge is covered is hard to compute, consider tolerance and specify that some edges can’t be covered, we break these edges. Then the extra edges can only be connected on top of a connected chunk of a contraction tree, which we can simply compute by dp, and we include the tolerance coefficients in the process of dp.

Suppose fu,if_{u,i} denotes the tolerance of uu in a subtree of ii with uu in a connected chunk of size ii. Each time a vv enumeration is merged, enumerate whether the edge of u,vu,v is broken, multiply by −1-1 if it is broken, otherwise count the contribution of 2i+j2^{i+j}.

Time complexity: O(n2)\mathcal O(n^2).

F. Half Mixed

  • Difficulty factor: 33.
  • Quality factor: 55.

If the number of submatrices is odd it’s done.

Otherwise you can solve by squashing the matrix into a row or column. Just take it greedily each time.

Time complexity: O(nm)\mathcal O(nm).

G. Meet in the Middle

  • Difficulty factor: 77.
  • Quality factor: 55.

Consider a point partition of a tree, hang the subtrees in the point partition tree on a second tree to build an imaginary tree and then switch the roots to calculate the furthest distance of each point and the next furthest distance of a point that is different from the furthest distance.

Time complexity: O((n+q)log⁡2n)\mathcal O((n+q)\log^2n).

H. P-P-Palindrome

  • Difficulty factor: 66.
  • Quality factor: 66.

It is easy to show that P,QP,Q are all shaped like nn ss tessellations, ss are palindromes, and P,QP,Q correspond to the same ss.

We build a generalised PAM and calculate the maximum repetition length of each palindrome.

The way to build a generalised PAM is to zero out cur after one string and move on to the next.

Time complexity: O((∑∣si∣)Σ)\mathcal O((\sum|s_i|)\Sigma).

I. Quartz Collection

  • Difficulty factor: 66.
  • Quality factor: 66.

The sum is fixed by putting (ai,bi)←(ai−bi,0)(a_i,b_i)\leftarrow (a_i-b_i,0). Then the first and second hands are obtained quite regularly, and are casually maintained with data structures.

Time complexity: O((n+q)log⁡n)\mathcal O((n+q)\log n).

J. Referee Without Red

  • Difficulty factor: 99.
  • Quality factor: 1010.

This kind of problem is usually just a matter of guessing some properties that feel right.

Firstly that rearrangement of the original question can be generalised to rearrange a row or a column in a given arrangement. We pull out the rings of each arrangement and line them up together, which is equivalent to giving the rows and columns neighbouring elements in a group. Operating on a row is equivalent to cyclically translating the group of all the columns in that row. Here is a possible simplified composition:

Consider a group of rows that has a size of 11, which brings in a contribution of lcm\text{lcm} from the intrinsically different scheme of all the grids in that row. Intrinsically different schemes can be computed using KMP with linear complexity.

We start by considering only one block’s, which is required to have both length and width greater than or equal to 22. We can shift its rows and columns cyclically, we can easily achieve the operation of exchanging adjacent bits, and then we can just row.

It would be wrong to just guess that the chunks are randomly handed over, and we must have some conditions that we haven’t considered, because the rows and columns are operated in parallel. Let’s start by examining the case where the elements in this block are two-by-two different:

Classical conclusion 1: A cyclic displacement of the sequence nn is equivalent to swapping n−1n-1 times.

Classical conclusion 2: Swapping two elements of a sequence changes the logarithmic parity of the reverse order of the sequence.

This reveals that if we arrange the elements in this block in any order, then if the row length is even, the operation on the column block changes the parity of the block’s inverse pair, and the row block similarly.

So the parity of each block’s reverse order pair is related to the number of operations on the rows and columns. One can think of abstracting a block into an edge, connected to a bipartite graph (if the rows don’t contribute to the inverse order pairs they are connected to 00, columns are the same). Then a point can choose parity, and the value of the edge is the dissimilarity of the point. The problem is sequences of essentially different edge weights.

This problem is usual, we pull out dfs for each connected block to generate a tree, then the tree edges are randomly adjusted, non-tree edges can be represented by tree edges. It’s done.

Time complexity: O(nm)\mathcal O(nm).

K. Security at Museums

  • Difficulty factor: unavailable\text{unavailable}.
  • Quality factor: unavailable\text{unavailable}.

I am not good at computational geometry.

L. Tavern Chess

  • Difficulty factor: 1.51.5.
  • Quality factor: 0.50.5.

taken attacks\text{taken attacks} What the hell does that mean?

Time complexity: O((n!)2)\mathcal O((n!)^2).

M. Vulpecula

  • Difficulty factor: 1010.
  • Quality factor: 1010.

Tech Question. The difficulty of this question is the merging of linear bases.

First assume that the capital letters A,B,C,…A,B,C,\dots etc. denote linear bases, that is, vectors that are linearly uncorrelated in Zn2\text{Z}_n^2. Suppose span(A)\text{span}(A) denotes the space into which the linear basis AA is tensored. A=BA=B if and only if span(A)=span(B)\text{span}(A)=\text{span}(B).

The addition of the following vectors ++ is a non-incremental addition, i.e., an iso-or. i,j∈Zn2i,j\in \text{Z}_n^2 is orthogonal if and only if popcount(i+j) mod 2=0\text{popcount}(i+j)\bmod 2=0.

We define an orthogonal linear basis A⊥A^\perp to a linear basis AA to denote the set of span(A)\text{span}(A) elements and span(A⊥)\text{span}(A^\perp) elements that are both orthogonal and \rank(A)+\rank(A⊥)=n\rank(A)+\rank(A^\perp)=n. We then dig into some elegant properties of A⊥A^⊥.

First consider the construction of A⊥A^\perp. We let the highbit\text{highbit} of each element in AA be two different, and write all the highbit\text{highbit} as key bits.

The process of constructing A⊥A^\perp is as follows, noting that A⊥A^\perp constructed by the following algorithm satisfies lowbit\textbf{lowbit} two different.

  • For each non-critical bit ii of AA, build an element of lowbit=i\text{lowbit}=i. Consider each j>ij>i case, and consider what the 2j2^j bits are, we just need to choose the right 0101 bits such that Ai⊥⊥AjA^\perp_i\perp A_j.

It can be shown that orthogonality is multiplicative. That is, a,b⊥ca,b⊥ c then ab⊥cab⊥c.

It is easy to see that every base of A⊥A^\perp is orthogonal to the base of AA, then span(A⊥)⊥span(A)\text{span}(A^\perp)\perp\text{span}(A).

We constructed out A⊥A^\perp, what does this do?

  • Lemma 11: S=span(A)S=\text{span}(A). Then the coefficients of each term of S^\hat S are either 00 or 2k2^k, where S^\hat S denotes the result of SS undergoing FWTXOR\text{FWTXOR} (Fast Walsh Transform). Assume k=\rank(A)k=\rank(A).

Proof: S∗S=2k×SS*S=2^k\times S (the left side is a heterogeneous convolution, the right side is a number multiplication. This proof is obvious)

Thus S^×S^=2k×S^\hat S \times \hat S=2^k\times \hat S (the left side is the corresponding bitwise multiplication)

The coefficients of the terms of S^\hat S are then 00 or 2k2^k.

  • Important Corollary: S^=2kspan(S⊥)\hat S=2^{k}\text{span}(S^\perp)

Proof: [xt]S^=∑s∈S(−1)popcount(s+t)[x^t]\hat S=\sum _{s\in S} (-1)^{\text{popcount(s+t)}}, can only have 2k2^k coefficients if tt is orthogonal to each ss. That is, t∈span(S⊥)t\in \text{span}(S^\perp).

  • Important application: span(A)∩span(B)=span((A⊥∪B⊥)⊥)\text{span}(A)∩\text{span}(B)=\text{span}((A^\perp∪B^\perp)^\perp).

Proof: our derivation below ignores constants, i.e., it only distinguishes 0101.

span(A)∩span(B)=span(A)×span(B)=A⊥^∗B⊥^=(A⊥∪B⊥)^=span((A⊥∪B⊥)⊥)\text{span(A)}∩\text{span(B)}=\text{span}(A)\times \text{span}(B)=\hat {A^\perp}*\hat {B^\perp}=\widehat{(A^\perp∪B^\perp)}=\text{span}((A^\perp∪B^\perp)^\perp)

By definition, it is known that A∩B=(A⊥∪B⊥)⊥A∩ B=(A^\perp∪B^\perp)^\perp.

So we have O(n2) \mathcal O(n^2) for linear basis merging.

Returning to the question, we just need to maintain the time of the earliest addition of each element to the linear base, sweeping twice from bottom to top to bottom. The query just needs to be greedy in the orthogonal sense.

Time complexity: O(nlog⁡2V)\mathcal O(n\log^2 V).

原文
存档评论2 条抓取于