The reason why the CDQ division and the whole two points together to study, because they are so much like the two ... Either the practice or the code ...
Feeling the whole dichotomy might be a little simpler than CDQ? So, first of all, learn the whole dichotomy. (Feeling their difference is that the whole dichotomy is the answer to each of the operational two, CDQ is the division of the sequence of operations)
The whole dichotomy is two points to the answer, and its specific operation is as follows:
(for example, zjoj2013k large number of queries)
Specific process
Step1. From (l,r) two-point answer. mid= (l+r) >>1, using a line segment tree to maintain the number of digits in the original sequence (A, b) larger than mid, and to record what the operation of the sequence is respectively.
Step2. Perform the given action.
1. If the operation is an insert, for example, a number c after each number between a B position
① if C > Mid adds one to the (A, B) section of the segment tree, and then modifies the action to mark 1;
② if C < Mid, the modification action is marked as 0;
2. If the operation is a query, if the segment tree (A, b) segment and greater than C, then the answer must be larger than mid, the modification action is marked as 1, otherwise the action is marked as 0.
Step3. Go to the next level. All marked with 0, divided into intervals (l,mid), marked as 1 in the interval (mid+1,r). (This will be sorted again.) can be merged (of course, very efficient), but direct sort is also possible.)
Until two points to l==r,l is the answer.
Each time the two points to the new answer, we want to empty the line tree directly. (Clear the flag at the root node, otherwise the interval is too large to blow up with memset)
and the current access interval does not intersect another section, in fact, always have an impact on our two-point answer, as long as the record of this effect can be, so do not need to consider it.
So we can see that the whole dichotomy is the constant division of the series, dividing the standard is the size of the numerical value. Therefore, its complexity is also positively correlated with the length of the sequence.
The proof of time complexity can be seen in the 2013 National training Team paper Xu Hao "several non-classical solutions to data structure problems"
If you do not want to go through the paper, I am very sweet to cite that piece of proof to the following (in fact, in order to deepen the understanding of the following I have to hit the hand):
Define T (c,s) to indicate that the second interval length is C, the length of the second sequence is S, it is advisable to set a single processing time complexity < Span class= "Mrow" id= "mathjax-span-3884" >o ( f ( n ) ) Then there are
T (c,s) =t ( C 2 , S 0 +t ( C 2 , S- S 0 )) +o (f (s))
Solution of T (C,n) ≤ O(F (N)Log C )
Note, as above, the proof is only O(F (N))≥O(N) is established.
After the specific topic, write a separate question. (Why don't you ask me why I don't write the same example as someone else?) I want to brush the amount of traffic and article volume AH 233)
"CDQ" CDQ division and the whole two-part study note Part1. Overall two points