ICPC Asia HongKong Regional Contest 2022 Solutions

· · 个人记录

A. TreeScript

Simple tree dp. Suppose f_u denotes the case where only u-subtrees are considered, v_1,v_2,\dots,v_m are all the sons of u, f_{v_i}<f_{v_{i+1}}, then f_u=\max(f_{v_1}+1,f_{v_2}+1,\dots,f_{v_{m-1}}+1 ,f_{v_m}).

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

Problem B. Big Picture.

This is a misread problem. The original idea was that the ith row (column) must be coloured with a prefix, and the probability of colouring the first j is p_{i,j}.

Clearly the black part will form a connected block, and the white part exists except for the outermost one which exists exactly where (i,j) meets (i+1,j),(i,j+1) both black. It is sufficient for each person to discuss the contribution.

Time complexity: \mathcal O(nm).

Problem C. Painting Grid

Firstly nm is even and 2^n\geq m,2^m\geq n. Let's assume that m is even.

We can make the first \left\lceil \log m\right\rceil rows satisfy the rows and columns are different and \tt 01 equal by construction:

After constructing the first \log row, you can construct two rows of two rows after that, just find a random S that hasn't appeared before and put it in the new row, and put all the inverses of S in the next row.

Finally, if there is a line left, just find a \tt 01 equal to the number of S that has not appeared and fill it in.

Time complexity: \mathcal O(nm).

Problem D. Shortest Path Query

Lemma: n\times n of lattice diagrams with convex packets of size not exceeding \mathcal O(n^{0.67}).

In this problem, the lower convex packet of each point can be built out, and the query can directly run the whole convex packet.

Time complexity: \mathcal O(n^{1.67}\log n+n^{0.67}q), not enough to run.

Problem E. Goose, goose, DUCK?

The problem asks us to count: the number of intervals in which each number occurs no more than k times.

For each colour, a section of the interval is ban dropped, and only one colour's interval changes as r is added.

So it becomes a problem of adding intervals and asking for the number of intervals 0. The line tree maintains the minimum value of the interval, the minimum number of intervals can be.

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

Problem F. Sum of Numbers

Note that in the optimal case the difference in length between neighbouring ends is no more than 1. Direct dfs is sufficient.

Time complexity: \mathcal O(\dfrac{3^k}{k}n).

Problem G. Paddle Star

Big points for discussing the problem. Equivalent to taking a hammer-like object and turning it at an angle to ask for area covered. The stick contribution can be counted directly. Just discuss the hammer part.

There are more situations.

Time complexity: \mathcal O(T).

Problem H. Another Goose Goose Duck Problem

Check. The answer is k\times b\times \dfrac{b+l-1}{b}. Round down.

Problem I. Range Closest Pair of Points Query

The ynoi problem that people love to see.

Consider first what to do with a single query. Consider that the answer is d, and we divide this plane in squares of l\times l (\dfrac l2<d\leq l). Then there will not be too many points within a block that are \mathcal O(1). We only need to look at the contributions generated by points within and between neighbouring blocks.

Enumerating l=2^0,2^1,\dots,2^{30} in turn is sufficient.

You see that this is very scalable, in that all we need to do to find dominant pairs is to look for a difference of no more than 3 in the number of each block that produces a contribution.

This looks like the dominant pairs are \mathcal O(n C\log n), with C being a large constant. The query is just a matter of dropping these dominant pairs into some data structure and checking the minimum of the interval.

Considering the large number of dominant pairs, we just need to make a \mathcal O(1)-\mathcal O(\sqrt n) chunk.

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

Problem J. Dice Game

The question asks you to find \dfrac{1}{n^2}\sum_{i=1}^n\max(ni,\sum_{j=1}^n i\text{ XOR }j) . Suppose f(i)=\sum_{j=1}^n i\text{ XOR } j-ni. Then you find that the positivity of f([1,n]) is roughly \mathcal O(\log), with i contributing independently to each binary bit, and it's just a matter of taking an individual dp and calculating the intervals and interval maxima.

Time complexity: \mathcal O(\text{can pass}).

Problem K. Maximum GCD

Just note that x can be manipulated to become a number between x or [1,\dfrac x2].

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

Problem L. Permutation Compression

Can magically delete the maximum value of a continuous segment of length l_i one at a time. Definitely delete from big to small, each time to find out the largest scalable segment (on this segment must be b elements, get a st table above the bisection) and then use the worst but can be satisfied with the magic can be, with set maintenance.

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