2019 Summer Hang two day5 test summary

T1

Subject to the effect

Blowing snow kept a cat, but the cat ran away, so she put cat scratch back.

Is well known, I am always like to run around the cat, but always gets in a strange place: strange place may be abstracted into a non m n points to FIG edges, and a length of a side is 1; blowing snow standing 1 point, and run away cat may appear on a label to any point in the 2..n.

To save time, blowing snow, it must follow the shortest path between two points.

Unfortunately, there is q events, each event has an edge will be destroyed, which makes some of the most original point can not be short-circuited come.

Blowing snow wondering how much the length of the shortest point to 1 point is changed before and after the i-th event.

sol

This question I think for a disjoint-set of practices, all possible are extracted on the side of the shortest way out to build a new map, and then will ask upside down and perform edging operations on the new map, and 1 in the same collection the point of most short-circuit unchanged.

Post-up but found not AC, the edges are directed, disjoint-set can not be directly combined to two sets:

the solid line is already edge, a broken line is added to the edge. Obviously we can not merge disjoint-set collection of 1 and 3 are located.

Correct answer is seemingly a very violent solution, the same will probably all be extracted in the shortest side of the road, construction of a new map, and 1 point in the same collection of the most short-circuit unchanged. Maintenance way: each point credited to a penetration, the degree of 0 to 1 and does not communicate with (except No. 1 dot). If the degree of a point is zero, then it will start side are deleted, the maintenance of other points, and sometimes may need to recursively deleted.

This approach appears to be very violent, but each side will only be deleted once, so complexity is \ (\ Theta (the n-+ m) \) .

T2

Subject to the effect

Xi Li likes to say is a poi~poi~girl.

One day, Xi Li picked up a written \ (n (n <= 10 ^ 7) \) uppercase letters paper. She found that these letters are all POIin one.

Out of poilove, Xi Li define a string such as a string of beautiful composition exactly POIthe number sequence.

她本想让你计算这个字符串的优美度,但仔细一想,这个问题太简单了。于是她提出了这样的问题:在原字符串中插入一个大写字母后最大的优美度是多少(可以插在开头和结尾或任意两个原有字母的中间)?

sol

先考虑计算原字符串的优美度,依次考虑每个字符,设\(f_1\)为出现了多少个P,\(f_2\)为出现了多少个PO,\(f_3\)为出现了多少个POI,每出现一个P,\(f_1\)++,出现O,\(f_2\)+=\(f_1\),出现I,\(f_3\)+=\(f_2\)。最终答案为\(f_3\)

很容易发现P一定插在最前,I一定插在最后,先把这种情况算出来。对于O,设\(pre_i\)为i之前有多少个P,\(las_i\)为i之后有多少个I,如果O插在第i个字符之后,优美度为原串的优美度加\(pre_i\times las_i\)\(\Theta(n)\)扫一遍即可。

解法应该到此为止,可串长有\(10^7\),优美度会爆long long,且不能用__int128,还要手写高精度。

T3

题目大意

长门和她的妹妹陆奥在玩臆象石。

臆象石是一种神奇的石头,每一块臆象石上都写着两个数字a[i]和b[i]。如果相邻的两块臆象石i和i+1满足gcd(a[i],a[i+1])>1,它们将可以融合在一起,并转化为b[i]+b[i+1]单位的石油(转化后两块石头都会消失,具体的转化方式参见样例2及其解释)。

由于臆象石的数量过多,长门使用了钞能力使得a[i]满足一些奇妙的性质。

请你帮助两姐妹确定转化顺序以获取尽可能多的石油。

臆象石数目为\(n,n<=6000\)

样例2

4
2 1
3 1
3 1
2 1
4

样例2解释:先删去第二和第三颗石子,使得第一和第四颗石子相邻。最后删去第一和第四颗石子

sol

我开始想了一个\(\Theta(n^3)\)的算法,设\(f(i,j)\)为i到j能否消掉,算出这个后就好写了,转移为\(f(i,j)=(f(i+1,j-1)\&\&gcd(a[i],a[j])>1)||(f(i,k)\&\&f(k+1,j),i<=k<j)\)

正解将这个转移进行了优化,从右往左依次计算,对于每个i,若\(f(i+1,j-1)\&\&gcd(a[i],a[j])>1\),则i向j连一条边,连完后从i跑dfs,若能到达j,则\(f(i,j)=1\),题目中的特殊性质为满足\(f(i+1,j-1)\&\&gcd(a[i],a[j])>1\)的情况为\(c\times n\)\(c\)为不大常数,则时间复杂度为\(\Theta(n^2*c+n^2log(n))\),前面是n次dfs,后面是连边的复杂度。

Guess you like

Origin www.cnblogs.com/hht2005/p/11402652.html