Experience and summary of line tree, Summary of line tree experience

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.