码迷,mamicode.com
首页 > 其他好文 > 详细

Segment Tree Range Minimum Query.

时间:2018-12-01 23:46:51      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:nim   pytho   put   inpu   gem   void   ||   mini   highlight   

int rangeMinQuery(int segTree[], int qlow, int qhigh, int low, int high, int pos) {
    if (qlow <= low && qhigh >= high) 
        return segTree[pos];
    if (qlow > high || qhigh < low)
        return maxVal;
    int mid = (low + high) / 2;
    return min(rangeMinQuery(segTree, qlow, qhigh, low, mid, 2*pos+1),
               rangeMinQuery(segTree, qlow, qhigh, mid+1, high, 2*pos+2));
}


void constructTree(int input[], int segTree[], int low, int high, int pos) {
    if (low == high) {
        segTree[pos] = input[low];
        return;
    }
    int mid = (low + high) / 2;
    constructTree(input, segTree, low, mid, 2*pos+1);
    constructTree(input, segTree, mid+1, high, 2*pos+2);
    segTree[pos] = min(segTree[2*pos+1], segTree[2*pos+2]);
}

  

 

Segment Tree Range Minimum Query.

标签:nim   pytho   put   inpu   gem   void   ||   mini   highlight   

原文地址:https://www.cnblogs.com/ruruozhenhao/p/10051343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!