链接:

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

Problem Description
In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,...,anrepresenting the size of the water source. Given a set of queries each containing 2 integers l and r, please find out the biggest water source between al and ar.
 
Input
First you are given an integer T(T≤10) indicating the number of test cases. For each test case, there is a number n(0≤n≤1000) on a line representing the number of water sources. n integers follow, respectively a1,a2,a3,...,an, and each integer is in {1,...,106}. On the next line, there is a number q(0≤q≤1000) representing the number of queries. After that, there will be q lines with two integers l and r(1≤l≤r≤n) indicating the range of which you should find out the biggest water source.
 
Output
For each query, output an integer representing the size of the biggest water source.
 
Sample Input
3
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
 
Sample Output
100
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)的更多相关文章

  1. (并查集)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 ...

  2. (二叉树)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)  ...

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

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

  5. hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online

    很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死…… 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了……没了! 反复读题,终于在偶然间 ...

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

  7. Hdu 5442 Favorite Donut (2015 ACM/ICPC Asia Regional Changchun Online 最大最小表示法 + KMP)

    题目链接: Hdu 5442 Favorite Donut 题目描述: 给出一个文本串,找出顺时针或者逆时针循环旋转后,字典序最大的那个字符串,字典序最大的字符串如果有多个,就输出下标最小的那个,如果 ...

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

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

随机推荐

  1. hadoop配置文件的参数含义说明

    #hadoop version 查看版本号 1 .获取默认配置 hadoop2系列配置文件一共包括6个,分别是hadoop-env.sh.core-site.xml.hdfs-site.xml.map ...

  2. jstatd - Virtual Machine jstat Daemon

    jstatd [options] 参数:options 命令行参数,可以按任何顺序,但如果有多余的或者中有互斥的参数,最后制定的那个参数将有优先权 options: -nr 当一个存在的RMI Reg ...

  3. dubbo 多协议和多注册中心

    一.配置dubbo多协议模式 1.默认协议 Dubbo缺省协议采用单一长连接和NIO异步通讯,适合于小数据量大并发的服务调用,以及服务消费者机器数远大于服务提供者机器数的情况.Dubbo缺省协议不适合 ...

  4. $(this).form("validate") 始终返回false

    onsubmit 提交前触发,返回 false 来阻止提交动作. validate 进行表单字段验证,当全部字段都有效时返回 true .该方法和 validatebox 插件一起使用. 解决:注释掉 ...

  5. e.g.-basic-Si

    ! Band structure of silicon. The points listed after plot1d below are the ! vertices joined in the b ...

  6. ECMAScript6新特性之继承

    class Animal{ constructor(name){ this.name = name; } get name(){ return this._name; } set name(val){ ...

  7. 配置Maven从私服下载构件

    --------------------siwuxie095                                     配置 Maven 从私服下载构件         从 Nexus ...

  8. .NET4.0的listview与DataPager的结合使用时的模板编辑

    1.设置listview模板样式: <asp:ListView ID="ListView1" runat="server" DataSourceID=&q ...

  9. .NET获得上传图片宽高

    代码: //图片大小限制--------------------------- System.Drawing.Image txtStoryimage = System.Drawing.Image.Fr ...

  10. 构建openssl debug版

    一.简介 作为一种安全协议,openssl囊括了主要的密码算法.常用的密钥和证书封装管理功能以及SSL协议,并提供了丰富的应用程序供测试或其它目的使用. 参考: http://www.linuxidc ...