【題目描述】
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 the result list.
Notice:We suggest you finish problem?Segment Tree Build,Segment Tree Query?and ?Segment Tree Modify?first.
給定一個(gè)整數(shù)數(shù)組(下標(biāo)由 0 到 n-1,其中 n 表示數(shù)組的規(guī)模),以及一個(gè)查詢列表。每一個(gè)查詢列表有兩個(gè)整數(shù)[start, end]。 對(duì)于每個(gè)查詢,計(jì)算出數(shù)組中從下標(biāo) start 到 end 之間的數(shù)的最小值,并返回在結(jié)果列表中。
【注】:在做此題前,建議先完成以下三道題線段樹(shù)的構(gòu)造,線段樹(shù)的查詢及線段樹(shù)的修改。
【題目鏈接】
www.lintcode.com/en/problem/interval-minimum-number/
【題目解析】
這道題目是篩選出Interval數(shù)組中的最小值,存入新數(shù)組。因此,聯(lián)想到Segment Tree Build和Segment Tree Query系列的題目,對(duì)于Interval的處理,使用線段樹(shù)是非常有效的方法。之前我們創(chuàng)建的線段樹(shù),有max和count兩個(gè)properties。參照max這個(gè)參數(shù),可以考慮在這道題增加一個(gè)min的參數(shù),代表每個(gè)結(jié)點(diǎn)的最小值。
【參考答案】