56 analog solution to a problem

A. Merchant

See a function, immediately thought of maintaining a convex hull, you may be able to maintain a large sum of the first m functions?

But thought does not maintain, then converted the next idea.

The answer appears monotonic: removing the answer is 0, the other must be monotonic.

The conclusion is obvious.

It might consider a combination.

Some functions once again and still function.

If the slope of a linear function of the total is greater than 0, more preferably greater then time, i.e. monotonic.

If the slope of the total primary function is less than or equal to 0, then the best time is 0, so the answer must be zero.

 

Then you can answer half, looking for the first m large statistics.

However Sort violence $ $, complexity is $ O (nlog ^ 2n) $, and can not fall over $ n = 10 ^ 6 $.

Use $ nth_element $, in fact, is the use of quick thinking row, but recursive half, the average complexity is $ O (n) $.

However, there are some details:

If the current value is less than 0, then the statistics are not the answer.

Explosion may add $ longlong $, can immediately $ return $ $ 1 $ in more than $ s $.

In fact, when the write $ sort $ attention to these details, however, later changed to $ nth_element $ when I forgot.

 

 

 

B. Equation

Given the tree is relatively simple equation.

Just push, it can be expressed as $ x_i $ $ x_1 $ and constants.

This constant actually found only on the weight of the chain of ancestors.

So Fenwick tree with dfs order to build and maintain what this constant yes.

Together with a given equation, a total of three equations, manually extract it (of course, these three equations complexity of Gaussian elimination play is right) .

 

 

 

C. Rectangle

Consider enumeration computing rectangle around the border, then the left and right borders must each choose a point.

The first is the simpler form:

Left and right boundaries have a point, then the two points Required.

Then the vertical rectangular section at least approximately $ Y $ current value of the boundary, are set to $ y_ {mn} $, $ y_ {mx} $.

Answer and internal regions of less than $ y_ {mn} $ greater than $ y_ {mx} $ Y $ value of about $.

答案为$(r-l)*\sum \limits_{y_i<y_{mn}}^{} \sum \limits_{y_j>y_{mx}}^{} y_j-y_i$

Guess you like

Origin www.cnblogs.com/skyh/p/11619487.html