Experience and summary of line tree, Summary of line tree experience
At the beginning, I learned the line segment tree and the zhx teacher. I used a sum array to replace the struct.
However, the sum array is hard to mark with lazy, and debugging is very difficult.
So I followed the instructor xxy to use the struct structure to store variables.
Although this method is easier to write than sum, it is easier to understand.
Basic operations on the Line Segment tree:
1. Single-point Modification
2. Single Point Query
3. interval modification (addition and subtraction)
4. interval Query
I have mastered it, But I just took a look at the train of thought and did not do it manually when I heard people say it was too tall and time-consuming.
When I typed a line segment tree, I came up with a rule and experience:
1. The size of the struct must be 4 * MAXN
2. All median m values are determined by the left and right intervals of the current tree (except for tree creation)
That is, m = (tree [k]. l + tree [k]. r)/2;
Instead of m = (ll + rr)/2;
However, you must follow the latter when building a project!
3. All the operations during mark-and-download are + =, rather than =!
4. When judging the interval, you must follow
If (tree [k]. l> = ll & tree [k]. r <= rr)
Format, otherwise it may cause a judgment error
5. When judging the range to be queried, you must follow
If (ll <= m) interval_change (k * 2, ll, rr, v );
If (rr> m) interval_change (k * 2 + 1, ll, rr, v );
Format, otherwise it is prone to errors!