Codeforces Round #588 (Div. 1)

Contest Page

Because some special reasons so more is not very timely ......

A

sol When not difficult to find someone diss everyone else when he must be deleted.

Maintain what everyone how many people will diss, when the number equal to the remaining $ -1 $, when the number of people diss put queue, each team take first update of the number of other people diss.

code

B

sol One conclusion: For the sequence $ a_1, a_2, ..., a_n $, $ gcd $ prefix does not exceed $ log_2a_i $ species. Considered from front to back calculate proved prefix $ gcd $, $ then from a $ i-1 $ I $ $ $ of GCD to a $ gcd $, divided by the value of either the same or at least $ 2 $.

So dfs $ gcd $ maintenance at each and every point of its range on the path to the root of the answer can be considered.

code

C

sol First operator answers can be enumerated triplet $ (i, j, k) $ $ a $ J can update the number of the answer by using the number of degrees. Come true appears to be directly contravened the map update violence is right, but my writing compare Kichiku:

according to the degree of root partition, to the degree $ \ leq \ sqrt {n} $ of violence, to the degree $ \ geq \ sqrt {n } $ degrees and $ \ geq \ sqrt {$ between the n-side violence}, for the degree $ \ geq \ sqrt {n} $ degrees and $ \ leq \ sqrt n $ edges between {}, the degree $ \ geq \ sqrt {n} $ point queue record with a lower number of $ \ leq \ sqrt {n} $ point to it, each time when the queue modified elements cleared. This complexity is clearly $ O (q \ sqrt {n }) $ a.

FIG built directly analyze anti complexity: setting each point is connected to the potential energy function of the number of its points, for the degree of $ \ leq \ {n} sqrt $ point thereof does not exceed the value of potential energy function $ \ sqrt { n} $ so every time complexity of the operation does not exceed $ \ sqrt {n} $; for the degree n $ \ geq \ sqrt {} $ point operation is not such that each of the potential energy function for these points and increase over $ \ sqrt {n} $, is shared equally so $ \ sqrt {n} $ a. Therefore, the complexity is $ O (q \ sqrt {n }) $.

code

D

sol Considered the first to write standard practice. Expand each row Lie Kangtuo first pressed into a number, then set $ f_ {i, j} $ I $ $ shows an arrangement through J $ $ replaced after a single transducer will be where. This can be $ O ((k!) ^ 2k ^ 2) $ do.

Enumeration right point $ r $ calculate the answer for all the left point. If we can consider the replacement has already changed from $ i $ $ j $ and even the edge $ (i, j) $, so now equivalent to the required points left after all this for all sides added to the list of where the $ 0 $ Unicom block size.

According to group theory and Lagrange's theorem, we can know that for the interval $ (1, r) is the most useful replacement $ only $ log_2k! $ Species, so the record about right for each point, each of the last occurrence replaced where, in every take a figure able to get $ 0 $ appears in the rightmost permutation permutation group added, can be reached by bfs update about the arrangement and the contribution of the answer. Complexity should be $ O ((k) ^ 2k ^ 2 + nk (k + log_2k)!!!) $ Is ......

however the above approach is very Kichiku, we consider that a fresh approach:

We believe that the edge $ (i right side, j) $ is able to become aligned arranged $ i $ $ j $ replacement of the latest time of occurrence, the edge is clearly useful only in maximum spanning tree on the graph. Every time we move the right end point is equivalent to adding $ k! $ Edges, using the Kruskal maintain it, and then find the bottleneck path length to each point $ 0 $ on a maximum spanning tree, then left when this point is less than equal to the length of time this arrangement can occur. So we used all bottlenecks path length and contributions answers on the line. This complexity should be $ O (nk! Log_2k!) $ Of? Anyway, I did not write.

code (superscript operator)

E1

sol Meet-in-the-middle. $ $ F_i disposed right represents $ R_1, R_2, R_3 $ three points can be set to match the left triples the probability of $ I $, I $ where $ is a $ \ binom {6} {3 } = 20 $ bit binary number, the first digit indicates the matching $ 0 $ $ (L_1, L_2, L_3) $, $ 1 $ indicates a first match $ (L_1, L_2, L_4) $, and so on. This thing can $ O (2 ^ {\ frac {n ^ 2} {2}} \ {n} {3} binom) $ burst search.

$ $ G_i then set the right represents $ R_4, R_5, R_6 $ can be matched to the complement of the left set of triples $ I $ probability, that indicates where a first bit indicates matching $ 0 $ $ (L_4, L_5, L_6 ) $, $ 1 $ indicates a first match $ (L_3, L_5, L_6) $, and so on.

We claim is $ \ \ limits_ {i} f_i \ sum \ limits_ {i \ land j = 0} g_j $, the rear portion of a prefix and a thing can be calculated high-dimensional sum.

I did not write the code

E2

sol A set $ 128 $ $ k $ bits which represents the current $ $ L subsets can match the current $ R $. Hall theorem due to various factors, the number of bipartite graph to meet the matching condition of $ k $ only $ S = 64184 $ species, we consider these states found out. We use bitset save $ k $, each time to consider adding a new point on the current $ R $, $ R $ enumerate even edge case and then update the value of $ k $. The complexity of this part can be done $ O (S \ frac {n2 ^ {2n}} {w}) $, it does not matter anyway slightly larger over-run.

In the process of using the search unordered_map the state together and hash newly added records point to the right side of the case they are even what time will be transferred to which state. Then DP: set $ f_ {i, j} $ $ represents the current R & lt determined even before the $ $ I $ edge points, match the current state is the probability of $ $ J. Transfer violence enumerate the current transfer point.

Complexity $ O (S \ frac {n2 ^ {2n}} {w} + nS2 ^ n) $.

code

F

sol Provided x_i $ $ $ I $ denotes the number of the coin $ i + 1 $, if $ x_i <0 $ indicates a number of coin from $ i + 1 $ to $ i $, $ x_0 = x_n $. When the note $ x_1, x_2, ..., x_n $ determined that we can easily construct a number of steps $ \ sum \ limits_ {i = 1} ^ n | x_i | $ protocol (and this is lower bound), it becomes a subject satisfying $ \ forall i, a_i - x_i + x_ {i-1} \ case in [l_i, r_i] $ case minimizing $ \ sum \ limits_ {i = 1} ^ n | x_i | $.

Enumeration $ $ x_1 and DP: set $ f_ {i, j} $ represents decided $ x_1, x_2, ..., x_i , x_i = j $ when $ \ sum \ limits_ {k = 1} ^ i | x_k | $ minimum value. Then $ f_ {i, j} $ on a $ f_ {i-1, k }, k \ in [l_i - a_i + j, r_i - a_i + j] $ transferred from. The initial value of $ f_ {1, x_1} = | x_1 |, f_ {1, others} = inf $.

The $ f_ {i, j} $ $ J $ considered to discrete function as arguments $ f_i (x) $, then the $ f_ {i-1} ( x) $ to $ f_ {i} (x) $ need to do these things: 1, the $ f_ {i-1} ( x) $ left translational $ (l_i - a_i) $ unit lengths; 2, so $ g (x) = \ min \ limits_ {i = x} ^ {x + (r_i -l_i)} f (i) $; 3, so that $ f_ {i + 1} ( x) = g (x) + | x | $.

Note that if $ f_ {i-1} ( x) $ is the convex hull so $ f_i (x) $ is the convex hull. And we can assume that $ f_1 $ the domain of only $ x_1 $, so $ f_i (x) $ is the convex hull. Convex hull for a very practical method is to maintain the slope of the line and the abscissa of the inflection point to maintain its right, so that the whole can be described as a convex hull.

$ 1 $ abscissa global operations to make a mark on the line, $ 2,3 $ operation a bit difficult to engage. $ 2 $ analyze the substance of the operation, assume the minimum value at the point to take $ p $, then the equivalent of $ [pt, p] $ $ inserting a slope segment of $ 0, then the left side of the bag left convex $ t $. $ 3 $ operated position corresponding to> 0 The slope of the line increases all $ 1 $, <0 for all segments of the slope of decrease of $ 1 $.

$ X $ interval to do a coordinate decrease, increase or decrease in the slope range, dynamic insertion inflection, seeking the global minimum problem. This will be apparent Treap solved, but a more excellent approach is to use two stacks are maintained to the right of the line slope $ \ all inflection GEQ 0 $ and <$ 0 $ and $ 1 $ operating a global tag, $ 2 $ operation <$ 0 $ corresponding to playing $ X $ stack coordinate marks, $ 3 $ marking operation is also, at this time so that at most only $ $ 1 by the line segments in a stack reach another stack.

We can find for a certain $ x_1 $ in $ O (nlogn) $ time The answer, we now need to address all of the answers minimum of $ x_1 $. Next is the magic time:

1, when $ x_1 $ is a real optimal solution unchanged. You can put this issue into a lower and upper bounds network flow problem, like candy delivery . According to a then I do not know how to prove theorems: the capacity and cost are integers of cost flow there must be an optimal solution to satisfy all sides flows are integers, then the optimal solution unchanged $ x_1 $ is a real number. The lemma will help us to expand the range of $ x_1 $ consists of an integer field to the real domain.

2, with two possible $ (x_1, x_2, ..., x_n) $ of the value of: $ (p_1, p_2, ... , p_n), (q_1, q_2, ..., q_n) $, then $ (c_1 = \ frac {p_1 + q_1} {2}, c_2 = \ frac {p_2 + q_2} {2}, ..., c_n = \ frac {p_n + q_n} {2}) $ is a set of possible $ (x_1, x_2, ..., x_n) $. Demonstrate consideration: $ a_i-p_i + p_ { i-1} \ in [l_i, r_i], a_i - q_i + q_ {i-1} \ in [l_i, r_i] $, and $ a_i - c_i + c_ {i -1} = \ frac {2a_i - (p_i + q_i) + (p_ {i-1} + q_ {i-1})} {2} = \ frac {1} {2} (a_i-p_i + p_ { i-1} + a_i - q_i + q_ {i-1}) $, while the two numbers in a range, then the average thereof is also apparent in this interval.

3, set $ f (x) $ $ x_1 = DP represented at the optimal solution x $ The derivation 2, if when $ x_1 = p_1 $ $ (p_1, p_2, ..., p_n) $ get to the most preferably, $ x_1 = q_1 $ time $ (q_1, q_2, ..., q_n) $ get to the optimum, then $ (r_1, r_2, ..., r_n) $ is a feasible set of solutions, it is not necessarily the most preferably, but because $ | r_i | = \ frac { | p_i + q_i |} {2} \ leq \ frac {| p_i | + | q_i |} {2} $, that is to say there will be $ \ sum | r_i | \ leq \ frac {\ sum | p_i | + \ sum | q_i |} {2} $, i.e., $ f (\ frac {p_1 + q_1} {2}) \ leq \ frac {f (p_1) + f ( q_1)} {2} $. The Jensen inequality, $ f $ function is a first order derivative of a monotonically increasing convex function, which has the minimum value.

So we only need to use the rule of thirds to find $ f (x) $ minimum on the integer field on it. Complexity $ O (nlognlog \ sum a_i) $.

Code is not written

Guess you like

Origin www.cnblogs.com/Itst/p/11621057.html