This is the Medium-Hard side, the creator of BDHIJL.

Part of my fault for the wrong schedule for question C. Originally, this was a simpler geometry problem, but in order to balance the difficulty, the meaning of the problem was slightly modified. It is not correct to apply the correct method of the original question to this question (if it is greater than180180^\circwhen). It is true that the questioning process is not standardized, and there is no good verification method. On the other hand, shortage of manpower (almost only two available labor qwq) is also one of the objective reasons.

My apologies to all contestants affected by Question C.

These questions are some interesting ideas I have accumulated over the past few months. In addition to the two temporarily added code questions, the remaining few questions are still very interesting qwq, but it is really difficult to put them in the CCPC sub-station, and the discrimination is not as good as expected.

Now this set of questions (except C) has been uploaded to Gym, and you can VP or submit questions on it. Hope to continue to play the value of these topics.

Below I will add more detailed solutions to these questions, as well as some of my views. Teams with training needs please do not check the solutions below.


B. Bounding Wall

A well-regulated data structure question.

First find that we cano(no+m)\mathcal{O}(n+m)Quickly maintains the length of white space that each square extends up/down/left/right. Suppose the currently queried block(i,j)(i,j)On the lower boundary, we enumerate the points corresponding to the upper boundary(k,j) (ki)(k,j)\ (k \le i). We also need a vertical border. We can find that the left and right sides are independent, and we can handle them separately. according tokkenumeration in descending order, starting with(i,p)(i,p)The vertical border extending upward will disappear at some point. At the same time the firstiiline and numberkkThe line also has the most extended length, so it becomes a vertical border asking if the prefix/suffix still exists. Binary using tree arrayso((no+m)qlog(no+m))\mathcal{O}((n+m)q\log(n+m))You can pass this question. The standard calculation uses the union search to point to the nearest survival point, and the time complexity iso((no+m)qalpha(no+m))\mathcal{O}((n+m)q\alpha(n+m)).

D. Defend City

My favorite question, maybe I will never be able to come up with such a good question in my lifetime. The meaning of the question itself is very simple: there are four kinds of points in the plane covering a certain direction1/41/4Plane, ask how many points can cover the entire plane at least.

All four directions require at least one point, and we record the point sets in the four directions asP1,P2,P3,P4P_1,P_2,P_3,P_4. For each point set, obviously only the points that are not covered by other points in the point set need to be left, and the remaining pointsthe yywithxxincreases and changes monotonically. Let each direction choose a subset QiPiQ_i\subseteq P_i. AssumeQiQ_iThe combined coverage area isSiS_i,AssumePiP_iThe combined coverage area isTiT_i.

Conclusion: There exists an optimal solution such that|Q1|=|Q3|=1|Q_1|=|Q_3|=1or|Q2|=|Q4|=1|Q_2|=|Q_4|=1.

Consider an optimal solution, assumingQ12Q_1\ge 2, any pair of adjacent pointsp,qp,q, observe the intersection of their covered areasrr. ifrrquiltQ2Q_2orQ4Q_4Points in the coverage, obviouslyQ1Q_1Deleting a point in can still cover the entire plane, contradicting the premise. SoQ1Q_1The intersection of all coverage areas inrir_ican only beQ3Q_3point coverage in . in turn,Q3Q_3withQ1Q_1the same way. consider laterQ1,Q3Q_1,Q_3The intersection point of the leftmost coverage area can cover allQ2Q_2The area that needs to be covered, that is,Q2,Q4Q_2,Q_4There is only one point.

Considering only the coverage areas of Q1 and Q3, the optimal solution must be shaped as shown in the figure above

Next may wish to make|Q2|=|Q4|=1|Q_2|=|Q_4| = 1,at this timeS1S_1andS3S_3The intersection point of the contour lines to fall intoT2T_2andT4T_4among, andS3S_3Contours are always onS1S_1Right and above the outline.

May wish to enumerateQ1Q_1The top point, we can greedily take the bestQ3Q_3The topmost point, the successor, is unique. sameQ3Q_3A point in also has a unique successor. Keep choosing the only successor until theT4T_4There is an intersection in .

Using doubling , one can doo(nologno)\mathcal{O}(n \log n)time complexity.

We can prove that when the answer5\ge 5, the optimal solutionQ1Q_1top pointpkp_konly one. which isT1T_1andT2T_2Contour intersection point, the point on the left or below (according to the direction of intersection).

forP1P_1middlethe yybigger pointptp_t, obviously the newly added coverage area ispkp_kSubsets of new coverage areas are added. forthe yysmaller pointptp_t, will make the corresponding inP3P_3successor inpthe sp_sworse. afterpthe sp_sexistP1P_1The successor inpkp_kNothing to do.

find this pointpkp_kcan directlyo(no)\mathcal{O}(n)simulated.

H. Holy Sequence

Examines familiarity with counting DPs and use of combined meaning.

Consider the DP equation for Stirling numbers of the second kind:the s[i][j]=the s[i1][j1]+the s[i1][j]js[i][j]=s[i-1][j-1]+s[i-1][j]*j, to find a combination meaning for it. if transferred asthe s[i1][j1]s[i-1][j-1], indicating that a new numberj+1j+1. if transferred asthe s[i1][j]js[i-1][j]*jIndicates adding a[1,j][1,j]number inxx. It can be found that any legal sequence is counted exactly once.

The transfer of DP is a DAG, then DP can be regarded as the path count of DAG, and the legal sequence and slave(0,0)(0,0)arrive(no,j)(n,j)The paths correspond one-to-one. Transfer edges are divided into two categories, which are marked here with different colors.

hypothetical figureskk appears in the legal sequencexxtimes, contributed tox2x^2. Combination meanings can be considered, expressed inxxindivualkkThe number of options selected twice in . There are two types of situations: the same position is selected twice, or different positions are selected. Here we only consider how to deal with choosing two different locations.

Different transfer edges correspond to different decisions (what number to put in which position). Since a certain number must not be the maximum value of the prefix after it appears for the second time , it can only be a yellow transfer edge.

In one case, as shown in the figure above, it is necessary to find the number of paths passing through these two transfer edges. Can go from left to right D(0,0)(0,0)Number of paths to the brown point, right to left DP(no,j)(n,j)to the number of purple points (additional state: whether a transfer edge is selected).

Another case is that the transfer edge on the left is a yellow transfer edge. This would make a prefixedkkTo make a contribution, just make a difference. The time complexity iso(no2)\mathcal{O}(n^2).

I. Interstellar Hunter

Comprehensive examination of basic linear algebra and number theory knowledge.

It can be proved that at any time, the reachable point set can be represented by two basis vectors . Represent the basis vectors in canonical form: one of the vectors(d,0) (d0)(d,0)\ (d \ge 0), another vector(x,the y) (x<d,the y0)(x,y) \ (x < d, y \ge 0). This can quickly merge after adding vectors.

Let the added vector be(a,b)(a,b), we can use(a,b)(a,b)with(x,the y)(x,y) Linear combination out(d',0)(d',0), then the newddthat isgcd(d,d')\gcd(d,d') up. empathy newthe yyforgcd(b,the y)\gcd(b,y)(vector(d,0)(d,0)will not contribute in this direction), use extended Euclidean to find the coefficients, and calculate the newxx.

special attentiond,x,the yd,x,yfor00Case. The time complexity iso(nolog(x+the y))\mathcal{O}(n \log(x+y)).

J. Jewel Splitting

Various tricks for hashing…

for eachdd, happens to haveno/d n/dsubsections: prefix + suffix. Calculate the hash values ​​of all prefix subsections and suffix subsections, and discretize them (in order to maintain the hash values ​​of the collection, convert them into sequence hashes). The enumeration prefix can dynamically maintain the number of occurrences of each sub-segment. In order to deduplicate, it is also necessary to maintain the hash value of the collection. Using a hash table to maintain a better time complexity requires writing a total of four different hashes. The time complexity iso(nologno)O(n \log n).

L. Lost Temple

Unexpectedly, no team passed this question qwq This is a question that requires imagination owo

The key property of this question is: the difference between the answers of two adjacent columns is at most11. Determine whether a column can be inxxDisappear after a year? Findings can be translated into whether theiiThe scale under the column isxxrhombus. It will be constrained by four directions and can be transformed into a four-time RMQ problem.

Since the answers in two adjacent columns differ by at most11, we can brute force enumerate the answers based on the previous column. At the same time, it is found that the interval of RMQ query is roughly monotonous, and monotonic queue maintenance can be used, and scattered segment violence (length at most22). Implementation still requires some superb skills, and at the same time maintain44monotonic queue and88pointer.


I'm about to retire, and I always wanted to make some small contributions to the algorithm competition circle...

Participating in the proposition of CCPC this time, even though I have some regrets, it can be regarded as a fulfillment of a small wish.

Hope you all enjoy these topics w