(线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5443
The Water Problem
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 738 Accepted Submission(s): 591
1
100
1
1 1
5
1 2 3 4 5
5
1 2
1 3
2 4
3 4
3 5
3
1 999999 1
4
1 1
1 2
2 3
3 3
2
3
4
4
5
1
999999
999999
1
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<cmath>
using namespace std; #define N 1110
#define INF 0xffffff
#define Lson r<<1
#define Rson r<<1|1
#define Mid a[r].mid() struct node
{
int L, R, Max;
int mid() {return (L+R)/;}
}a[N*]; int n, m; void BuildTree(int r, int L, int R)
{
a[r].L = L, a[r].R = R, a[r].Max = ; if(L==R)
{
scanf("%d", &a[r].Max);
return ;
} BuildTree(Lson, L, Mid);
BuildTree(Rson, Mid+, R); a[r].Max = max(a[Lson].Max, a[Rson].Max);
} int Query(int r, int L, int R)
{
if(a[r].L==L && a[r].R==R)
{
return a[r].Max;
} if(R<=Mid)
return Query(Lson, L, R);
else if(L>Mid)
return Query(Rson, L, R);
else
{
int LMax = Query(Lson, L, Mid);
int RMax = Query(Rson, Mid+, R);
return max(LMax, RMax);
}
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int i, L, R; scanf("%d", &n); BuildTree(, , n); scanf("%d", &m);
for(i=; i<=m; i++)
{
scanf("%d%d", &L, &R);
printf("%d\n", Query(, L, R));
}
}
return ;
}
(线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)的更多相关文章
- (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )
http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others) Memo ...
- (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)
http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others) ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...
- hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online
很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死…… 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了……没了! 反复读题,终于在偶然间 ...
- HDU 5437 Alisha’s Party (优先队列)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- Hdu 5442 Favorite Donut (2015 ACM/ICPC Asia Regional Changchun Online 最大最小表示法 + KMP)
题目链接: Hdu 5442 Favorite Donut 题目描述: 给出一个文本串,找出顺时针或者逆时针循环旋转后,字典序最大的那个字符串,字典序最大的字符串如果有多个,就输出下标最小的那个,如果 ...
- Hdu 5446 Unknown Treasure (2015 ACM/ICPC Asia Regional Changchun Online Lucas定理 + 中国剩余定理)
题目链接: Hdu 5446 Unknown Treasure 题目描述: 就是有n个苹果,要选出来m个,问有多少种选法?还有k个素数,p1,p2,p3,...pk,结果对lcm(p1,p2,p3.. ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU - 5441 (离线+并查集)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5441 题意:给你n,m,k,代表n个城市,m条边,k次查询,每次查询输入一个x,然后让你一个城市对(u,v ...
随机推荐
- Jquery和Ajax
jQuery 是一个 JavaScript 函数库.JavaScript 是 HTML5 以及所有现代浏览器中的默认脚本语言! jQuery 库包含以下特性: HTML 元素选取 HTML 元素操作 ...
- sqlserver列重命名
EXEC sp_rename 'tablename.[OldFieldName ]', 'NewFieldName', 'COLUMN'
- css 设置元素背景为透明
要设置某一元素的背景为透明,在 chrome .firefox.opera 下是这样的: rgba 中的最后一个参数 0.4 就是想要的透明度,范围在0-1之间. 在 ie 中一般是这样的: filt ...
- hivepython 实现一行转多行
案例1: ==效果等同于一行转多行 数据表名称:zhangb.gid_tags 数据格式,每行是2个字段,(gid,tags) ,可能有脏数据,分隔符为“\t”, ANDROID-9de77225 ...
- show_space查看对象空间使用情况
CREATE OR REPLACE PROCEDURE show_space(p_segname IN VARCHAR2, p_owner IN VARCHAR2 DEFAULT USER, p_ty ...
- Linux就业技术指导(七):游戏类运维重点流程解析
一,某游戏公司例行上线与更新流程示例 例行维护/更新流程 1.1 更新前天 提前确认好要更新的是什么,更新会有人通知你,一般是运营人员 比如:我们明天做什么什么更新 1.2 第2天更新 一般固定点更新 ...
- gtftools软件简单介绍(我自己不建议用,因为我发现不好用)
1)背景 生物信息学研究经常涉及计算或提取基因的各种特征,如基因ID作图,GC含量计算和不同类型的基因长度,通过操纵基因模型,这些模型通常以GTF格式注释,可从ENSEMBL或GENCODE数据库获得 ...
- express中使用ejs
[express中使用ejs] 1.添加 ejs 依赖. npm install ejs --save 2.设置 view engine 为 ejs 即可.
- MVC001之权限校验
参考网址:http://bbs.csdn.net/topics/370002739 http://blog.csdn.net/chenloveyue/article/details/7095522 h ...
- React Native 填坑一
React Native 填坑一 关于RN的布局 分为主轴和交叉轴, 主轴可以是横向也可以是竖向,交叉轴也是对应的. 主轴默认是竖向.如果要更改用flexdirection 主轴对齐方式:justif ...