Lintcode206 Interval Sum solution 题解

【题目描述】

Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers[start, end]. For each query, calculate the sum number between index start and end in the given array, return the result list.

Notice:We suggest you finish problem Segment Tree Build,Segment Tree Query and Segment Tree Modify first.

给定一个整数数组(下标由 0 到 n-1,其中 n 表示数组的规模),以及一个查询列表。每一个查询列表有两个整数[start, end]。 对于每个查询,计算出数组中从下标 start 到 end 之间的数的总和,并返回在结果列表中。

【注】:在做此题前,建议先完成以下三题:线段树的构造线段树的查询,以及线段树的修改

【题目链接】

www.lintcode.com/en/problem/interval-sum/

【题目解析】

此题可使用区间树解决。注意interval各有一部分处于root左侧和右侧的问题。

【参考答案】

www.jiuzhang.com/solutions/interval-sum/

作者:程风破浪会有时
链接:https://www.jianshu.com/p/392580830b21
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

原文地址:https://www.cnblogs.com/admondguo/p/8452137.html

时间: 2024-10-16 02:18:20

Lintcode206 Interval Sum solution 题解的相关文章

Lintcode20 Dices Sum solution 题解

[题目描述] Throw n dices, the sum of the dices' faces is S. Given n, find the all possible value of S along with its probability. Notice:You do not care about the accuracy of the result, we will help you to output results. 扔 n 个骰子,向上面的数字之和为 S.给定 Given n,

Lintcode207 Interval Sum II solution 题解

[题目描述] Given an integer array in the construct method, implement two methods query(start, end) and modify(index, value): For query(start,end), return the sum from index start to index end in the given array. For modify(index,value), modify the number

Interval Sum I && II

Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers [start, end]. For each query, calculate the sum number between index start and end in the given array, return the result l

Lintcode30 Insert Interval solution 题解

题目描述] Given a non-overlapping interval list which is sorted by start point.Insert a new interval into it, make sure the list is still in order and non-overlapping (merge intervals if necessary). 给出一个无重叠的按照区间起始端点排序的区间列表.在列表中插入一个新的区间,你要确保列表中的区间仍然有序且不重叠

Lintcode205 Interval Minimum Number solution 题解

[题目描述] Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers[start, end]. For each query, calculate the minimum number between index start and end in the given array, return th

Lintcode: Interval Sum

Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers [start, end]. For each query, calculate the sum number between index start and end in the given array, return the result l

Lintcode: Interval Sum II

Given an integer array in the construct method, implement two methods query(start, end) and modify(index, value): For query(start, end), return the sum from index start to index end in the given array. For modify(index, value), modify the number in t

Lintcode202 Segment Tree Query solution 题解

[题目描述] For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding Segment Tree, each node stores an extra attribute max to denote the maximum number in the interval of the array (index from start to end). 对于一个

Lintcode17 Subsets solution 题解

[题目描述] Given a set of distinct integers, return all possible subsets. Notice:Elements in a subset must be in non-descending order;The solution set must not contain duplicate subsets. 给定一个含不同整数的集合,返回其所有的子集 注意:子集中的元素排列必须是非降序的,解集必须不包含重复的子集 [题目链接] http:/