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. 【题解】AT2043 AND Grid

    [题解]AT2043 AND Grid 我们考虑直接构造两个互补的图切分别联通的图,然后原图有的大家都有就构造完成了. #include<iostream> #include<cst ...

  2. centos安装php5.6

    配置yum源 追加CentOS 6.5的epel及remi源. # rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel- ...

  3. Cglib学习报错 java.lang.reflect.InvocationTargetException-->null

    package javacore.testForCglibProxy; import java.lang.reflect.Method; import net.sf.cglib.proxy.Enhan ...

  4. (转)浅析三层架构与MVC模式的区别

    MVC模式介绍: MVC全名是Model ViewController,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用于组织代码用一种业务逻辑和数据 ...

  5. MySQL——事务

    核心知识: 1.什么是事务?一组原子性的SQL查询语句 2.事务的四种属性:ACID 3.四种隔离级别:读取未提交内容.读取提交内容.重复读.串行化. 4.什么是幻读?幻读有那些解决办法?连续读取同一 ...

  6. PAT 甲级 1005. Spell It Right (20) 【字符串】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...

  7. BMP文件解析【转】

    本文转载自:http://blog.csdn.net/Blues1021/article/details/44954817 BMP文件通常是不压缩的,所以它们通常比同一幅图像的压缩图像文件格式要大很多 ...

  8. <J2EE学习笔记>关于Servlet的讲义

    题外话:接触java又是半年之前的事情了,当初好好学了java却把cpp给忘了,到现在又把手里发热的cpp给放下重新捡起来java,究竟这两种OOP语言我能不能清晰分开记住呢 以下全部课件来自于同济大 ...

  9. 分享知识-快乐自己:oracle表分区详解

    从以下几个方面来整理关于分区表的概念及操作: 1)表空间及分区表的概念: 2)表分区的具体作用: 3)表分区的优缺点: 4)表分区的几种类型及操作方法: 5)对表分区的维护性操作: 1):表空间及分区 ...

  10. hdu1521排列问题

    题目链接 利用指数型母函数解决排列问题 1.口袋中有白球2个,红球3个,黄球1个,任取3个作为一个排列,总共有多少种排列? 类似地用指数型母函数解决 用(1+x/1!+x2/2!)表示取白球0个,1个 ...