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.的更多相关文章

  1. Range Minimum Query and Lowest Common Ancestor

    作者:danielp 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAnc ...

  2. AOJ DSL_2_A Range Minimum Query (RMQ)

    Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0,a1,...,an−1} with the ...

  3. Geeks - Range Minimum Query RMQ范围最小值查询

    使用线段树预处理.能够使得查询RMQ时间效率在O(lgn). 线段树是记录某范围内的最小值. 标准的线段树应用. Geeks上仅仅有两道线段树的题目了.并且没有讲到pushUp和pushDown操作. ...

  4. RMQ(Range Minimum Query)问题(转)

    问题描述 RMQ问题是求给定区间中的最值问题.对于长度为n的数列A,回答若干查询RMQ(A, i, j).返回数组A中下标在[i,j]里的最小值的下标. 比如数列 5,8,1,3,6,4,9,5,7 ...

  5. Leetcode: Range Sum Query - Mutable && Summary: Segment Tree

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  6. Leetcode: Range Sum Query 2D - Mutable && Summary: Binary Indexed Tree

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  7. Segment Tree Query I & II

    Segment Tree Query I For an integer array (index from 0 to n-1, where n is the size of this array), ...

  8. Lintcode: Segment Tree Query II

    For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ...

  9. Lintcode: Segment Tree Query

    For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding ...

随机推荐

  1. nodejs搭建简单的websocket服务端

    创建websocket服务端使用了nodejs-websocket ,首先要安装nodejs-websocket,在项目的目录下: npm install nodejs-websocket 1.搭建w ...

  2. SDUT OJ 河床

    河床 Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 地理学家们经常要对一段河流进行测量分析.他们从上游开始向下游方向等距离地选择 ...

  3. js动态插入标签代码(insertAdjacentHTML)

    做网页时通过ajax请求获取到数据后,有的需要把数据拼接到带有各种标签的字符串中,拼接完字符串就需要把字符串动态添加到网页上的某个位置,举个

  4. Html+CSS3技术实现动画、天气图标动态效果 效果很酷

    1. [代码][CSS]代码    <svg    version="1.1"    id="sun"    class="climacon c ...

  5. CentOS7 网络管理工具nmcli

    今天帮别人调试虚拟机的网络问题(CentOS 7系统),习惯性直接改/etc/sysconfig/network-scripts/ifcfg-xxx配置文件,但是不知道为什么重启network后静态i ...

  6. Java编程思想(18~22)

    第18章 Java I/O系统 18.1 File 类 18.1.1 目录列表器 18.1.2 目录实用工具 18.1.3 目录的检查及创建18.2 输入和输出 在Java 1.0中类库的设计者限定于 ...

  7. Java微信公众平台开发_03_消息管理之被动回复消息

    GitHub源码:https://github.com/shirayner/weixin_gz 一.本节要点 1.回调url 上一节,我们启用服务器配置的时候,填写了一个服务器地址(url),如下图, ...

  8. css书写规则

    无规矩不成方圆,不管有多少人共同参与同一项目,一定要确保每一行代码都像是同一个人编写的 不要在自闭合(self-closing)元素的尾部添加斜线 不要省略可选的结束标签(closing tag)(例 ...

  9. CSS实现简单无缝滚动

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 递归/非递归----python深度遍历二叉树(前序遍历,中序遍历,后序遍历)

    递归代码:递归实现很简单 '二叉树结点类' class TreeNode: def __init__(self, x): self.val = x self.left = None self.righ ...