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]);
}
Segment Tree Range Minimum Query.的更多相关文章
- Range Minimum Query and Lowest Common Ancestor
作者:danielp 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAnc ...
- 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 ...
- Geeks - Range Minimum Query RMQ范围最小值查询
使用线段树预处理.能够使得查询RMQ时间效率在O(lgn). 线段树是记录某范围内的最小值. 标准的线段树应用. Geeks上仅仅有两道线段树的题目了.并且没有讲到pushUp和pushDown操作. ...
- RMQ(Range Minimum Query)问题(转)
问题描述 RMQ问题是求给定区间中的最值问题.对于长度为n的数列A,回答若干查询RMQ(A, i, j).返回数组A中下标在[i,j]里的最小值的下标. 比如数列 5,8,1,3,6,4,9,5,7 ...
- 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 ...
- 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 ...
- 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), ...
- Lintcode: Segment Tree Query II
For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ...
- 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 ...
随机推荐
- 我的Java开发学习之旅------>在Dos环境下Java内部类的编译和运行
习惯了在IDE工具上进行代码编写,连最基本的Javac命令和Java命令都忘记的差不多了,今天对一个Java内部类进行编译和运行的时候,就出糗了.IDE是把双刃剑,它可以什么都帮你做了,你只要敲几行代 ...
- 转载 j2ee j2se j2me 区别,mvc 和ssh联系理解
[转]J2SE J2EE J2ME的区别 以及 MVC与SSH对应关系 2014-3-6阅读322 评论0 J2SE J2EE J2ME的区别多数编程语言都有预选编译好的类库以支持各种特定的功能,在J ...
- (转)Ubuntu10.04编译FFmpeg
刚开始安装折腾了好久,很多软件包都找不到,可能是跟软件源有关,所以先说一下我的软件源: 软件源是用的中国默认的官方源http://cn.archive.ubuntu.com/ubuntu/ 一.安装编 ...
- angularJs-未加载完成的页面显示混乱ng-bind
ng-bind 未初始化完成不加载数据,避免产生{{}}导致页面混乱 还是上边的例子,当前页面没有加载完成的时候,页面显示是不完整的会频繁的出现{{}}这样子的表达式语句,给用户的感觉很不和谐,所以使 ...
- Java for LeetCode 132 Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- Java基础教程:面向对象编程[2]
Java基础教程:面向对象编程[2] 内容大纲 访问修饰符 四种访问修饰符 Java中,可以使用访问控制符来保护对类.变量.方法和构造方法的访问.Java 支持 4 种不同的访问权限. default ...
- cetons 怎么强制卸载 PHP
查看php版本命令: #php -v 这个命令是删除不干净的 #yum remove php 因为使用这个命令以后再用 #php -v 还是会看到有版本信息的..... 必须强制删除 #rpm -qa ...
- C++配置Opencv
https://blog.csdn.net/qq_17550379/article/details/78201442
- BZOJ 1041 [HAOI2008]圆上的整点:数学【费马平方和定理】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041 题意: 给定n(n <= 2*10^9),问你在圆x^2 + y^2 = n^ ...
- Mac替换sublime图标
下载.icns格式一个图标:http://www.easyicon.net/language.en/iconsearch/sublime/ 终端执行:open /Applications/Sublim ...