当前位置:网站首页>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
边栏推荐
- Lambda end operation find and match findany
- [zeloengine] localization process /imgui Chinese culture
- Redis persistence mode AOF and RDB
- Lambda termination operation Max & min
- Single chip microcomputer: MODBUS multi computer communication program design
- 10 minutes to thoroughly understand how to configure sub domain names to deploy multiple projects
- Answer private message @ Tiantian Wx //2022-6-12 C language 51 single chip microcomputer led analog traffic light
- [MySQL] index and transaction
- Summary of meeting between president Ren and scientists and experts in system engineering
- Redis data persistence
猜你喜欢

Solution to failure to download files by wechat scanning QR code

Single chip microcomputer: basic concepts of a/d and d/a

The data obtained from mongodb query data command is null

120. 三角形最小路径和-动态规划

No more! Another member of the team left..

Differences and relations between three-tier architecture and MVC

R: Employee turnover forecast practice

Redis data persistence

Interpretation and implementation of proxy mode

【LeetCode】860. Change with lemonade (2 brushes for wrong questions)
随机推荐
Checkmarks and crosses to collect
Redis数据持久化
MCU: RS485 communication and Modbus Protocol
出现Could not find com.scwang.smart:refresh-layout-kernel:2.0.3.Required by: project :app 无法加载第三方包情况
MCU: EEPROM multi byte read / write operation sequence
ROS topics and nodes
Ego planner code analysis ----cmakelists Txt and package xml
February 25, 2021 (Archaeology 12 year Landbridge provincial competition)
Billions of data to determine whether the element exists
Redis
[test development] file compression project practice
Common terms of electromagnetic compatibility
Promise combined with await
Goframe day 5
Summary of meeting between president Ren and scientists and experts in system engineering
SCM: introduction and operation of EEPROM
Answer private message @ Tiantian Wx //2022-6-12 C language 51 single chip microcomputer led analog traffic light
[笔记]vs2015 编写汇编masm32之使用MASM32库
[Yugong series] June 2022 Net architecture class 081 API customization task of distributed middleware schedulemaster
Use the visual studio code terminal to execute the command, and the prompt "because running scripts is prohibited on this system" will give an error