当前位置:网站首页>Explanation of line segment tree
Explanation of line segment tree
2022-06-13 04:17:00 【csx_ zzh】
What is a segment tree ?
Line segment tree , It's a kind of Binary search tree . It divides an interval into several Unit interval , Each node stores an interval . it Powerful , Support interval summation , Interval maximum , Interval modification , Single point modification and other operations .
Each node of the line tree stores an interval [L…R] Information about , among Leaf node L=R .
Its general idea is : Divide a large interval equally into 2 Between communities , Each cell is divided equally into 2 It's a small area …… And so on , Up to the... Of every interval L be equal to R( In this way, the interval only contains the information of one node , Can't be divided ). By modifying these intervals 、 Inquire about , To achieve the modification of the large interval 、 Inquire about .
thus , Every single point of modification 、 The time complexity of a single point query is only O (logn) .
The basic structure and construction of line segment tree
The length of each segment tree is not 1 The interval of is divided into left and right intervals to solve recursively , The whole line segment is divided into a tree structure , The information of the interval is obtained by merging the information of the left and right intervals . This data structure can easily perform most interval operations .
There is a size of 5 Array of a={10,11,12,13,14}, To convert it to a segment tree , There are the following ways : Let the root node number of the segment tree be 1, Using arrays d To save our segment tree ,di It is used to save the segment tree numbered i The value of the node ( The value maintained by each node here is the sum of the intervals represented by this node ).
1. Why drive 4 Times the interval ?
2. Delay marking : Add a new tag in the node structure , Record whether this node will be modified , Modification of any interval , We first divide it into nodes in the segment tree by interval query , Then modify the information of these nodes , And mark these nodes . When modifying and querying , If we get to a node P, And continue to view its child nodes , So we have to look at the nodes P Whether it's marked , If there is , You need to modify the information of the child node first according to its tag , And the child nodes are marked with the same marks , Also cancel the node P The tag , This operation is called tag dropping , Also called pushDown
It's understandable , Suppose grandpa wants to give new year's money to his two granddaughters , So Grandpa gave his son the total lucky money first , Let the son give it to the daughter
, But the son thinks his daughter is too young , Temporarily unavailable , So I saved it first . Suddenly one day, Grandpa was going to ask his granddaughter if she got the lucky money , At this time, dad was worried , I quickly gave my daughter the lucky money
边栏推荐
- Uni app enables pull-up loading and pull-down refresh (pull-down with animation)
- [kubernetes series] pod chapter actual operation
- Hugo 博客搭建教程
- Single chip microcomputer: main index of a/d (analog-to-digital conversion)
- Manage PC startup items
- Lenovo notebook computer uses the insert key. When the mouse becomes a small square, how to solve it
- This Sedata uses multiple methods to dynamically modify objects and values in arrays. Object calculation properties
- Introduction to RFM analysis
- Differences and relations between three-tier architecture and MVC
- ROS中的msg消息
猜你喜欢
出现Could not find com.scwang.smart:refresh-layout-kernel:2.0.3.Required by: project :app 无法加载第三方包情况
Value of line height
Understand the pseudo static configuration to solve the 404 problem of refreshing the page of the deployment project
VGA display based on de2-115 platform
How to use debounce in lodash to realize anti shake
干预分析 + 伪回归
Mongodb compass connects to the Alibaba cloud remote server database or reports an error occurred while loading instance info: command hostinfo req
Single chip microcomputer: pcf8591 application program
Differences and relations between three-tier architecture and MVC
[test development] basic concepts related to testing
随机推荐
Hugo blog building tutorial
Real time requirements for 5g China Unicom repeater network management protocol
JSTL -- JSP standard tag library
Configuration and practice of shardingsphere JDBC sub database separation of read and write
[test development] installation of test management tool Zen path
Alipay native components (hotel time selection)
基于DE2-115平台的VGA显示
十亿数据量 判断元素是否存在
Principle, composition and functions of sensors of Dajiang UAV flight control system
[test development] file compression project practice
Use ASE encryption and decryption cache encapsulation in Vue project
Summary of meeting between president Ren and scientists and experts in system engineering
Lambda end operation count
Lambda end operation find and match findfirst
MVP framework for personal summary
Single chip microcomputer: infrared remote control communication principle
120. triangle minimum path sum - Dynamic Planning
Redis数据持久化
Milliards de données pour déterminer si un élément existe
EMC整改纲要