lintcode-线段树查询II-247
2015-09-24 22:11
330 查看
/* class SegmentTreeNode { * public: * int start, end, count; * SegmentTreeNode *left, *right; * SegmentTreeNode(int start, int end, int count) { * this->start = start; * this->end = end; * this->count = count; * this->left = this->right = NULL; * } * } */ class Solution { public: int query(SegmentTreeNode *root, int start, int end) { if(!root||start>end) return 0; if(start<=root->start&&end>=root->end) return root->count; int mid=root->start+(root->end-root->start)/2; if(start>mid) return query(root->right,start,end); else if(end<mid+1) return query(root->left,start,end); else return query(root->left,start,mid)+query(root->right,mid+1,end); } };
相关文章推荐
- 纯虚函数
- 转载老师的一篇文章——java自学之路
- CGI,fastcgi和php-fpm
- CGI,fastcgi和php-fpm
- margin和padding的区别
- shell脚本学习 一
- ZOJ 2369 | SGU 217 | Acdream 1234 自适应辛普森积分
- NYOJ 837 Wythoff Game(威佐夫博奕公式利用)
- USB host 通信
- 一个关于java数据库驱动包的小发现
- 2015年9月20日第一节课html2-2
- js中return、return true、return false的区别
- asp.net中SQL语句太长,怎么换行写?
- ubuntu 安装numpy和matplotlib
- 手游发展迅猛,渠道要搭建移动游戏生态圈才有出路
- 系统分析和设计工具
- noip模拟小象涂色
- poj 3070 Fibonacci 【矩阵快速幂】
- ZOJ.2421 Recaman's Sequence【暴力打表】 2015/09/24
- python syntax points