最后更新

二刷

09-Jna-2017

利用线段树进行区间查找,重点还是如何判断每一层的覆盖区间,和覆盖去见与当前NODE值域的关系。

public class Solution {

    public int query(SegmentTreeNode root, int start, int end) {
if (root == null) return 0;
if (start > root.end || end < root.start) return 0; int coveredStart = Math.max(start, root.start);
int coveredEnd = Math.min(end, root.end);
if (root.start == coveredStart && root.end == coveredEnd) return root.count; return query(root.left, coveredStart, coveredEnd) +
query(root.right, coveredStart, coveredEnd);
}
}

247. Segment Tree Query II的更多相关文章

  1. Lintcode: Segment Tree Query II

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

  2. Lintcode247 Segment Tree Query II solution 题解

    [题目描述] For an array, we can build a Segment Tree for it, each node stores an extra attribute count t ...

  3. 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), ...

  4. 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 ...

  5. [LintCode] Segment Tree Build II 建立线段树之二

    The structure of Segment Tree is a binary tree which each node has two attributes startand end denot ...

  6. 202. Segment Tree Query

    最后更新 二刷 09-Jan-17 正儿八经线段树的应用了. 查找区间内的值. 对于某一个Node,有这样的可能: 1)需要查找区间和当前NODE没有覆盖部分,那么直接回去就行了. 2)有覆盖的部分, ...

  7. 439. Segment Tree Build II

    最后更新 08-Jan-2017 开始介绍线段树的主要作用了,可以快速在区间查找极值,我猜是这样的..... 一个NODE的最大值取决于它左边和右边最大值里大 按个,所以,所以什么?对了,我们该用po ...

  8. Segment Tree Build I & II

    Segment Tree Build I The structure of Segment Tree is a binary tree which each node has two attribut ...

  9. Lintcode: Segment Tree Modify

    For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...

随机推荐

  1. EEPROM的存储大小

    学习单片机时,常见的EEPROM如24C02的大小为2Kbit(有的也称2KB).这里的2KB到底能存储多少数据呢? 2KB中,B表示单位bit,K表示1024. 单片机编程中常用的数据类型为unsi ...

  2. 查看python关键字

    打开命令窗口 输入python-——help()——keywords

  3. luogu P2078 朋友

    题目背景 小明在A公司工作,小红在B公司工作. 题目描述 这两个公司的员工有一个特点:一个公司的员工都是同性. A公司有N名员工,其中有P对朋友关系.B公司有M名员工,其中有Q对朋友关系.朋友的朋友一 ...

  4. Day01:我的Python学习之路

    1.Python是什么语言? Python是动态的解释性的强类型定义的语言. (1)动态语言与静态语言 ①静态语言:在编译期间就会去做数据类型检查的语言,如C,C++. ②动态语言:在运行期间才会去做 ...

  5. UVA-1625-Color Length(DP LCS变形)

    Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...

  6. [模板] LIS

    树状数组优化LIS到nlogn,网上找了好多,感觉讲得都不是很明白,正好自己复习整理一下. 基本的DP方程 f[i]=max(f[i],f[j]+1) (j<i且a[j]<a[i]) 定义 ...

  7. js layui 分页脚本

    //分页 layui.use(['laypage'], function(){ var laypage = layui.laypage; laypage.render({ elem: 'page' , ...

  8. Python数据可视化库-Matplotlib(一)

    今天我们来学习一下python的数据可视化库,Matplotlib,是一个Python的2D绘图库 通过这个库,开发者可以仅需要几行代码,便可以生成绘图,直方图,功率图,条形图,错误图,散点图等等 废 ...

  9. jQuery.data() 的实现方式

    jQuery.data() 的作用是为普通对象或 DOM Element 附加(及获取)数据. 下面将分三个部分分析其实现方式:     1. 用name和value为对象附加数据:即传入三个参数,第 ...

  10. luogu2596 [ZJOI2006]书架

    treap.树是以"优先级"(优先级越小,在书架上越靠上)形成的,堆是以rand()的权值形成的.还要再维护一个原编号. 置顶/置底:找到那个元素,把它拉出来修改优先级再塞回去. ...