zoukankan      html  css  js  c++  java
  • Segment Tree Range Minimum Query.

    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]);
    }
    

      

    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    Tinkoff Challenge
    Tinkoff Challenge
    Tinkoff Challenge
    Tinkoff Challenge
    整体二分
    树链剖分+LCT
    上下界网络流
    莫队
    可并堆
    bzoj_1033: [ZJOI2008]杀蚂蚁antbuster
  • 原文地址:https://www.cnblogs.com/h-hkai/p/10051343.html
Copyright © 2011-2022 走看看