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 ...
随机推荐
- NFT是什么,有什么前景?
去年 11 月,Crypokitties 的发布给加密货币的世界带来了风暴,有些加密猫的价格甚至涨到了 30 万美元,以太坊网络拥堵不堪,平均贡献了当时以太坊网络30%的交易额.当 Cryptokit ...
- get_linux_ip_info.sh 获取ip地址
linux 获取ip地址 get_linux_ip_info.sh #!/bin/bash #/告诉使用者,这程序的用户是从ipconfig 命令中获取IP地址 echo "该程序是从命令中 ...
- python manage.py shell 的增删改查
python manage.py shell 的增删改查 guoguo-MacBook-Pro:myblog guoguo$ python manage.py shell Python 3.5.1 ( ...
- struts 与 Java Web应用简介
struts实质上就是JSP Model2的基础上实现的MVC框架. 在Struts框架中,模型有实现业务逻辑的JavaBean或EJB组件构成 视图由一组JSP文件构成. 控制器 控制器由Actio ...
- ABAP 关键字(1)
1.定义DATA ,TYPES TYPES关键字用于创建自定义数据类型,就像JAVA里面创建类一样,用TYPES创建的数据类型可以被其它变量引用(类似于实例化对象),而本身不能直接引用或者赋值. DA ...
- Gemini.Workflow 双子工作流入门教程五:业务表单开发
简介: Gemini.Workflow 双子工作流,是一套功能强大,使用简单的工作流,简称双子流,目前配套集成在Aries框架中. 下面介绍本篇教程:业务表单开发. 业务表单开发 业务表单的开发,和在 ...
- 笔记 jsp/ajax/js/jquery/html5/css+div->table
1. jsp 1).jsp(39,33) equal symbol expected: 这个异常是说第39行有 " '( 冒号单引号)问题 2)${map[key]} map和key换 ...
- HDU2825 Wireless Password —— AC自动机 + 状压DP
题目链接:https://vjudge.net/problem/HDU-2825 Wireless Password Time Limit: 2000/1000 MS (Java/Others) ...
- line -1: Validation of SOAP-Encoded messages not supported
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" ...
- 微软面试题:鸡蛋从第N层及以上的楼层落下会摔破
from:https://blog.csdn.net/qq_18425655/article/details/52326709 题目: 有一栋楼共100层,一个鸡蛋从第N层及以上的楼层落下来会摔破 ...