Segment tree entry (Summary)

  • Tags: tree line

This article mainly from Bowen, "[full version] segment tree" NotOnlySuccess Great God several years ago in a blog, because of the time some years old now can not find the god of the original blog post, so compiled some information online, in restore it here.

Code style

  • maxnIs subject to the maximum range, while the number of nodes to open four times, the exact number of nodes is greater than the minimum maxn to open the \ (2_x \) twice;
  • lsonAnd rsonrepresent the nodes and the right son of the left son, because each time the parameters are transmitted is fixed to these variables, it can be more convenient represented by a predefined;
  • push_up(int rt) The information is updated to the current node's parent node;
  • push_down(int rt) It is to update the information of the current node to node son;
  • rt It represents the current sub-tree root (root), which is the node currently resides.

Questions Categories

  • Single-point update : most basic tree line, update only the leaf node, and then use the information push_up(int rt)in this update function up;
  • Into segments update :( Normally this is a hurdle) need to use delay mark (or lazy mark) for beginners, it simply is not updated when each update in the end, the delay makes updating delayed until the next mark We need to update or to ask the time;
  • Interval consolidation : These topics will ask longest continuous interval interval to meet the conditions, so push_upthe need for a hand around his son's range to merge;
  • Scan line : These topics require some sort operation, from left to right and then swept past with a scanning line (of course, is our mind), is the most simple and rectangular area, perimeter and other issues.

Single-point update

https://www.cnblogs.com/codedecision/p/11676957.html

Into segments update

https://www.cnblogs.com/codedecision/p/11687527.html

Interval merger

No.

Scan line

No.

Guess you like

Origin www.cnblogs.com/codedecision/p/11687537.html