区间数据结构-线段树
文章平均质量分 95
介绍线段树的数据结构实现和相关题目
memcpy0
希望探索文理结合的自由之路。
展开
-
LeetCode 729. My Calendar I【设计;有序集合,二分查找;线段树】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还建立了相关的。原创 2023-09-10 20:20:03 · 246 阅读 · 0 评论 -
LeetCode 731. My Calendar II【设计,有序映射,差分;线段树】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还建立了相关的。原创 2023-09-10 20:07:43 · 334 阅读 · 0 评论 -
LeetCode 732. My Calendar III【设计,有序映射,差分;线段树】困难
A k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.)You are given some events [start, end), after each given event, return an integer k representing the maximum k-booking between all原创 2021-05-16 03:19:03 · 379 阅读 · 1 评论 -
LeetCode 2569. Handling Sum Queries After Update【数组,线段树】困难
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2023-07-27 13:08:00 · 202 阅读 · 0 评论 -
LeetCode C++ 1649. Create Sorted Array through Instructions【树状数组/线段树/归并排序/平衡树】困难
Given an integer array instructions, you are asked to create a sorted array from the elements in instructions. You start with an empty container nums. For each element from left to right in instructions, insert it into nums. The cost of each insertion is t原创 2020-12-26 02:15:28 · 622 阅读 · 0 评论 -
LeetCode C++ 307. Range Sum Query - Mutable【Binary Indexed Tree/Segment Tree】中等
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at index i to val.Example:Given nums = [1, 3, 5]sumRange(0, 2) -> 9update(1, 2)原创 2020-12-09 02:08:23 · 196 阅读 · 0 评论 -
【数据结构Java实现】线段树【数组实现】
文章目录线段树Segment Tree一、线段树介绍二、线段树基础实现三、创建线段树线段树Segment Tree一、线段树介绍在竞赛题目中,线段树(区间树)是经常出现的一类题目。LeetCode上面也有线段树的问题。普通的树是以一个个元素作为结点的,而线段树是以一个个区间作为结点的,它适用于对区间进行操作的题目。一个很有意思的问题是——染色问题:e.g.e.g.e.g. 对于一面墙,长...原创 2020-03-30 01:53:28 · 838 阅读 · 0 评论