Well, for a more pleasant reading experience, please go to http://mlz000.logdown.com/posts/252433-mo-algorithm-summary
First known is the MO team algorithm is to ask the first left end of the block to sort, and then the right end of the sorting complexity of the first card, interested students can own yy under or consult the information below to give a few examples of detailed explanation
1. Little Z's Socks Description: Given a sequence m asks each query: The interval selects two numbers, the probability of two numbers equalif the probability is the output0/1carefully observed, so that the X-tableExample xnumber of occurrences, the [l,r] area is queried each timewhen the answer is
if we know [L,r] Districtthe number of occurrences of each x in the room, using the tableto indicate the current answer with ansThen we can consider that when we start [l,r] as [l,r+1] the effect on ANS is known only the change of this value affects our answer, and it is easy to see that the answer is
Think about whyIn other cases, think of yourself. So each transfer is, the total complexityCode
2.Codeforces 86D (yandex.algorithm 2011) Almost identical to Little Z's socks. Mo Team Template Code
3.bzoj 3289 (Mato file Management) Description given a sequence of M queries per query: Interval In reverse logarithm is obviously found can be used in the tree array + MO team 艹 the past, each modification is, you can pass the code these questions are basically a routine, learning the MO team basically will be because each query is a continuous interval, We can easily find a contribution to the answer after each move. So, what if it's not normal to ask for a range of sequences, but to ask for a two-point path on the tree? Yes, this is the legendary ...
The tree, MO team
Let me give you an example.
1.Spoj 10707 Count on a tree II (COT2) Description given the number of n nodes on a tree, M asks each question: the number of different values in the interval, how does this TM do? The interval is not continuous AH! Isn't this team going to make it? Don't panic, we have a magical thing called
DFS sequence
We can mark each node with a timestamp, l[u],r[u] respectively, we use the nature of the Dfs order, we can convert the two-point path to a continuous interval (also need to consider the problem of LCA, think about, why) Yes, so we can block the DFS sequence, MO Team! God Ben to see that now the words should be done, Konjac Konjac or continue to elaborate on the practice of defining >_< as a collection of vertices on a path, root represents the root node
Definition, we do not care about the LCA, if we go from the path to the path of the answer has any impact on it? By definition we can get
so we can getThat is, each update can also be the path of V-v ' (except LCA (V,V ')) the existence of the point to reverse can actually we record is T, and then each time the existence of LCA (V,V ') change it to the S statistical answer and then the LCA (V,V ') The existence of the restore change back to T on the line in fact, the reader can change the DFS sequence to help understand >_< and then the problem has been solved, the DFS sequence will be divided into the DFS sequence interval problem, consider LCA can be
Code
2.WC 2013 Candy Park (UOJ 58) Description uh.. The topic is too long children's shoes see for yourself >_< poke here in short it is necessary to modify the ~ well, presumably see here, we have a certain understanding of MO Team Algorithm and the tree on the team algorithm has already had some knowledge we found before we do the problem is only the query has not been modified, then there is modified can not do it? That's not true. If we can do it without modification, the change is equal to the addition of a time dimension into three-dimensional we can press the left endpoint as the first keyword, the right end is the second keyword, time for the third keyword sort preprocessing before each modification of the color, And this revised color MO team to inquire about the sort of each query found with the last time not simultaneously violence t++,t--simultaneously modify the color and the answer can (use before preprocessing) and then solve the time problem is normal two-dimensional MO team if we set the size of the block, divided into blocks equal to the inquiry into a block, Each moving distance is B, each block moves up to nBecause N and q are the same order, so the total complexity is, so get the best and then the code is ~code end Sprinkle flowers! (Mother egg from 10 to write to now finally is finished, touching, the consciousness may be wrong, many forgive >_<
Mo Team Algorithm summary