Mo team understand notes

Background : This is the team Mo algorithm. Why is it called Mo teams algorithm it? It is said the 2010 National Team Mo Tao (3) mentioned this method in the job.

Since Mo Tao captain often do play, we call him Mo team, this algorithm is also known as Mo Team algorithm ... (Taken: aaa.com )

 

Mainly used to write some of the more outstanding of violence. . . Of course, be used with caution in case slower than n ^ 2 of it ...

Details : first ordering! First sort! First sort! ! !

   Complexity pay attention! pay attention! pay attention! Other than n ^ 2 slow ah, right to shoot down a block size of what a tune or simply write n ^ 2 ...

   Complexity more critical during telescopic, typically O (1).

    Lesser time and can be considered to use offline.

Online good words : " Taken here: aaa.com"

  1. If the data is small, an array, the time complexity is O (1); if the data is large, can be considered a discrete or map, the time complexity is O (logn).

  2. For example, six interrogation as follows: (1, 100), (2, 2), (3, 99), (4, 4), (5, 102), (6, 7).

  The data has been sorted in accordance with the left point. Upon treatment with the method described above, the left end point 6 moves, moves the right end will move 98 + 97 + 95 + 98 + 95 = 483 times. The right end of a significant move back and forth, seriously affected the time complexity - the complexity of sorting is O (mlogm), the number of all the left end points move only as O (n), but asking the right end point of each mobile O (n) , there are m inquiry, so the total number of mobile O (nm), the total number of mobile O (mlogm + nm). The upper bound of the running time has not diminished.

 

  In fact, we asked slight changes the order of processing can be better: (2, 2), (4, 4), (6, 7), (5, 102), (3, 99), (1, 100 ).

 

  Moving to the left the number of point 1 + 2 + 2 + 2 + 2 = 9, slightly more than the original. Point moves to the right the number of 3 + 2 + 3 + 1 + 95 = 104, the number of movements of the right end greatly reduced.  

 

Operation : The block-based (that's wrong understanding), is divided into several blocks and maintenance query (by stretching), by ordering our left and right endpoints become less mobile.

Guess you like

Origin www.cnblogs.com/three-D/p/11240658.html