hdu 5443(线段树水)
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
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.
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 <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(线段树水)的更多相关文章
- hdu 1754 线段树 水题 单点更新 区间查询
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 1754 I Hate It(线段树水题)
>>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...
- hdu 3974 线段树 将树弄到区间上
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4533 线段树(问题转化+)
威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- 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 ...
- hdu 3436 线段树 一顿操作
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 3397 线段树双标记
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 4578 线段树(标记处理)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others) ...
- hdu 2871 线段树(各种操作)
Memory Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- Python入门:Python基础笔记
(C语言:)C语言是相对C++.C#.Java等语言更接近底层,并且一些硬件编程都可以使(只能使用)C语言.另外C语言学起来相对困难,因为涉及到指针,指针也是语言接近底层语言的一个特征.目前编写较大的 ...
- 服务器TIME_WAIT和CLOSE_WAIT分析和解决办法
先上两张图: 查看TIME_WAIT和CLOSE_WAIT数的命令: netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a ...
- Python中的字典与集合
今天我们来讲一讲python中的字典与集合 Dictionary:字典 Set:集合 字典的语法: Dictionary字典(键值对) 语法: dictionary = {key:value,key: ...
- java web项目(spring项目)中集成webservice ,实现对外开放接口
什么是WebService?webService小示例 点此了解 下面进入正题: Javaweb项目(spring项目)中集成webservice ,实现对外开放接口步骤: 准备: 采用与spring ...
- debian软raid
http://www.linuxidc.com/Linux/2013-06/86487.htm
- 电商平台API接口
- 将json的文本文件转换为csv文件
import pandas as pd import fire import glob import json def text_to_csv(file_name): json_data = json ...
- Js 希望某链接只能点击一次
<a onclick=”function(){...}”> 希望这连接只能执行一次 <a onclick=”function(){...}; this.onclick()=funct ...
- Nginx报 No input file specified. 的问题解决之路 转
https://m.aliyun.com/yunqi/articles/34240 今天接手公司的一个项目,照例将项目clone下来,配置本地host,nginx,然后访问. 怎么回事?迅速在php的 ...
- Welcome-to-Swift-02基本运算符
运算符是检查,改变,合并值的特殊符号或短语.例如,加号+将两个数相加(如let i = 1 + 2).复杂些的运行算例如逻辑与运算符&&(如if enteredDoorCode &am ...