[Optimization] sort of cattle-off practice match 54D

 

 

Cattle-off practice match 54D

Practice is the subject of violence:

Array m (m <= 100) within the current cycle length for each n (n <= 5e5) of the sort again, substantially take the first small k (k <= 100).

I can think of that comparison approach is preferred: in m cycles through the data and the data to fit the size of the queue into monotone, monotone ensure that the number of data queues <= k, then continue with a new element is determined HOL size of the element, update the answer. Yet still out.

Game solution to a problem is to say:

  Author: Sovietqwq✨

  Links: https://ac.nowcoder.com/discuss/342616?type=101&order=0&pos=1&page=1

  Source: Cattle-off network
  for the current interval l, rl, rl, r, a randomly selected element costi, i∈ [l, r] as the reference number base. Then maintains two pointers, the base interval is less than all of the elements into the base of the left side, the right side is greater than the base element into the base . This step can be O (interval length) is completed.
When the end of the two pointers is provided (i.e., base) in the p-position. p left elements are smaller than base, the right elements are greater than p base (may be equal, does not affect the answer). So we count the number of elements of the left p t, if t≥k recursively to the interval [l, p]; otherwise the answer plus all the cost of the left p, k- = t, recursively to the interval [p + 1, r] .
Complexity of T (n) = T (2n ) + O (n) = O (n). The total complexity of O (nm).

 

Then, do not timed out! ....

 

Then, also learned a thing:

It can be large random number.

:: RD random_device STD; 
STD :: mt19937 are MT (RD ()); // or directly: STD :: mt19937 are MT (Time (0)); 
int main () 
{ 
    int A = MT ()% MOD; 
    the printf ( " % D " , A); 
}

 

 

Guess you like

Origin www.cnblogs.com/kkkek/p/11871649.html