Official

E - Two Increasing Sequences Editorial by evima


Consider the highest bit among the bits where \(A\) changes. By the strict monotonicity of \(A\), the bits are arranged as \(000\ldots111\). This division into blocks of \(0\) and \(1\) bisects the ordering of \(A_i \oplus X\). Based on this observation, the answer is always No when the following condition is not satisfied:

  • All nodes in the Permutation Tree of \(P\) are linear nodes.

Below, we consider the case where this condition is satisfied.

We perform tree DP on the Permutation Tree. Define \(d[x]\) as “when considering only the interval of \(P\) represented by vertex \(x\), what is the minimum number of lower bits needed to express the ordering relations in that interval?” At each subtree merge, it suffices to solve the following subproblem:

  • You are given a length-\(n\) integer sequence \(c=(c_1,c_2,\ldots,c_n)\). Perform this operation \(n-1\) times: choose adjacent elements \(c_i,c_{i+1}\) and replace them with \(\max(c_i,c_{i+1})+1\). Find the minimum possible final value of \(c_1\).

For this subproblem, it suffices to pick the \(i\) minimizing \(\max(c_i,c_{i+1})\) (breaking ties by taking the smallest \(i\)) and merge those.

Implement the above tree DP, and output Yes if \(P\) can be fully represented by the given \(X\), and No otherwise.

Note that leading \(0\)s in \(X\) can also be used.

posted:
last update: