The Water Problem

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1308    Accepted Submission(s): 1038

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,...,an representing 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 <stdio.h>
#include <string.h>
using namespace std; const int Max = ;
int MAXNUM;
int a[Max];
struct Tree{
int Max;
int r,l;
}t[*Max];
int MAX(int k,int j){
if(k>=j) return k;
return j;
}
void build(int idx,int l,int r){
t[idx].l = l;
t[idx].r=r;
if(l==r){
t[idx].Max = a[l];
return;
}
int mid = (l+r)>>;
build(idx<<,l,mid);
build(idx<<|,mid+,r);
t[idx].Max = MAX(t[idx<<].Max,t[idx<<|].Max); //父亲节点 }
void query(int idx,int l,int r,int L,int R){
if(l>=L&&r<=R) {
MAXNUM = MAX(MAXNUM,t[idx].Max);
return;
}
int mid = (l+r)>>;
if(mid>=L)
query(idx<<,l,mid,L,R);
if(mid<R)
query(idx<<|,mid+,r,L,R);
} int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
build(,,n);
int m;
scanf("%d",&m);
for(int i=;i<=m;i++){
int l,r;
scanf("%d%d",&l,&r);
MAXNUM = -;
query(,,n,l,r);
printf("%d\n",MAXNUM);
}
}
}

hdu 5443(线段树水)的更多相关文章

  1. hdu 1754 线段树 水题 单点更新 区间查询

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. hdu 1754 I Hate It(线段树水题)

    >>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...

  3. hdu 3974 线段树 将树弄到区间上

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. hdu 4533 线段树(问题转化+)

    威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

  5. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  6. hdu 3436 线段树 一顿操作

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  7. hdu 3397 线段树双标记

    Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

  9. hdu 2871 线段树(各种操作)

    Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

随机推荐

  1. Ubuntu 18.04安装显卡驱动

    安装完双系统,我遇到好几次开机或关机有问题,导致我重装了3次系统,第三次我才知道是显卡驱动问题,Ubuntu预装的开源Nvidia驱动太烂了,需要换官方驱动. 把 nouveau 驱动加入黑名单 $s ...

  2. angular4使用代理

    1. 在angular-cli项目根目录下创建proxy.config.json { "/api/v1": { "target": "http://1 ...

  3. destoon 配置文件config.inc.php参数说明

    $CFG['db_host']数据库服务器,可以包括端口号,一般为localhost $CFG['db_user']数据库用户名,一般为root $CFG['db_pass']数据库密码 $CFG[' ...

  4. JS中如何操作数组

    背景:随笔中所应用到的代码来自于上一篇随笔,MVC&JQuery如何根据List动态生成表格,部分代码不再重复. 代码如下: $("#btnTan").click(func ...

  5. Linux学习-开放源码的软件安装与升级简介

    什么是开放源码.编译程序与可执行文件 我们说过,在 Linux 系统上面,一个文件能不能被执行看的是有没有可执行的那个权限 (具有 x permission),不过,Linux 系统上真 正认识的可执 ...

  6. git push后是空目录,且提示modified content, untracked content

    最近往自己的github传代码时,每一步都正常,但最后push上去之后是空目录,且在本地执行git status时提示: 后来发现是由于push的工程下本来就有个.git目录,所以才导致push上去的 ...

  7. 持续化集成Jenkins的系统配置

    最近在研究selenium2自动化测试,用到持续化集成jenkins.由于之前仅限于使用,而没有真正动手配置过,所以现在学习从零开始,搭建持续化集成,故而有了这篇博客. 先介绍一下项目持续集成测试,这 ...

  8. foy: 轻量级的基于 nodejs 的通用 build 工具

    npm 的 scripts 下写的命令太多就很容易很乱,各种第三方轮子都只能解决一部分问题,总感觉不是很好用,想找个类似 make 的工具只能找到 jake, 可是 jake 的 API 太老,居然很 ...

  9. Ext.js二级联动

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link href ...

  10. [python学习篇][廖雪峰][4]函数--reduce

    reduce的用法.reduce把一个函数作用在一个序列[x1, x2, x3...]上,这个函数必须接收两个参数,reduce把结果继续和序列的下一个元素做累积计算,其效果就是: reduce(f, ...