【題目描述】
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左側和右側的問題。
【參考答案】