跳到正文

个人记录

ICPC Asia HongKong Regional Contest 2022 Solutions

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

文章信息

发布
2023年12月31日
收录
2026年2月10日
更新
2026年11月9日
篇幅
约 12 分钟

版本

  1. v1当前

A. TreeScript

  • Difficulty factor: 44.
  • Code power factor: 22.

Simple tree dp. Suppose fuf_u denotes the case where only uu-subtrees are considered, v1,v2,…,vmv_1,v_2,\dots,v_m are all the sons of uu, fvi<fvi+1f_{v_i}<f_{v_{i+1}}, then fu=max⁡(fv1+1,fv2+1,…,fvm−1+1,fvm)f_u=\max(f_{v_1}+1,f_{v_2}+1,\dots,f_{v_{m-1}}+1 ,f_{v_m}).

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

Problem B. Big Picture.

  • Difficulty factor: 55.
  • Coefficient of force: 33.

This is a misread problem. The original idea was that the iith row (column) must be coloured with a prefix, and the probability of colouring the first jj is pi,jp_{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)(i,j) meets (i+1,j),(i,j+1)(i+1,j),(i,j+1) both black. It is sufficient for each person to discuss the contribution.

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

Problem C. Painting Grid

  • Difficulty factor: 77.
  • Code power factor: 66.

Firstly nmnm is even and 2n≥m,2m≥n2^n\geq m,2^m\geq n. Let’s assume that mm is even.

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

  • Write binary to the first m2\dfrac m2 column and the inverse of ii binary to the m2+i\dfrac m2+i column.

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

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

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

Problem D. Shortest Path Query

  • Difficulty factor: 66.
  • Code power factor: 66.

Lemma: n×nn\times n of lattice diagrams with convex packets of size not exceeding O(n0.67)\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: O(n1.67log⁡n+n0.67q)\mathcal O(n^{1.67}\log n+n^{0.67}q), not enough to run.

Problem E. Goose, goose, DUCK?

  • Difficulty factor: 44.
  • Code power factor: 66.

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

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

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

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

Problem F. Sum of Numbers

  • Difficulty factor: 33.
  • Code power factor: 55.

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

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

Problem G. Paddle Star

  • Difficulty factor: 66.
  • Code power factor: 66.

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: O(T)\mathcal O(T).

Problem H. Another Goose Goose Duck Problem

  • Difficulty factor: 0.50.5.
  • Code force factor: 0.50.5.

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

Problem I. Range Closest Pair of Points Query

  • Difficulty Factor: 99.
  • Code Force Factor: 77.

The ynoi problem that people love to see.

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

Enumerating l=20,21,…,230l=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 33 in the number of each block that produces a contribution.

This looks like the dominant pairs are O(nClog⁡n)\mathcal O(n C\log n), with CC 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 O(1)−O(n)\mathcal O(1)-\mathcal O(\sqrt n) chunk.

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

Problem J. Dice Game

  • Difficulty factor: 88.
  • Code power factor: 77.

The question asks you to find 1n2∑i=1nmax⁡(ni,∑j=1ni XOR j)\dfrac{1}{n^2}\sum_{i=1}^n\max(ni,\sum_{j=1}^n i\text{ XOR }j) . Suppose f(i)=∑j=1ni XOR j−nif(i)=\sum_{j=1}^n i\text{ XOR } j-ni. Then you find that the positivity of f([1,n])f([1,n]) is roughly O(log⁡)\mathcal O(\log), with ii 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: O(can pass)\mathcal O(\text{can pass}).

Problem K. Maximum GCD

  • Difficulty factor: 44.
  • Code force factor: 33.

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

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

Problem L. Permutation Compression

  • Difficulty factor: 66.
  • Code Power Factor: 66.

Can magically delete the maximum value of a continuous segment of length lil_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 bb 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: O(nlog⁡n)\mathcal O(n\log n).

原文