【线段树】HDU 5443 The Water Problem
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5443
题目大意:
T组数据。n个值,m个询问,求区间l到r里的最大值。(n,m<=1000)
题目思路:
【线段树】
线段树裸题。求区间最大值。
//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 1004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int t[N<<];
void change(int l,int r,int a,int k,int x)
{
if(a>r || a<l || l>r)return;
if(l==r && l==a){t[k]=x;return;}
change(l,(l+r)/,a,k+k,x);
change((l+r)/+,r,a,k+k+,x);
t[k]=max(t[k+k],t[k+k+]);
}
int query(int l,int r,int a,int b,int k)
{
if(l>r || l>b || r<a)return ;
if(a<=l && r<=b)return t[k];
int mid=(l+r)/,x1,x2;
x1=query(l,mid,a,b,k+k);
x2=query(mid+,r,a,b,k+k+);
return max(x1,x2);
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,l,r,x;
for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
memset(t,,sizeof(t));
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&x);
change(,n,i,,x);
}
scanf("%d",&m);
for(i=;i<=m;i++)
{
scanf("%d%d",&l,&r);
printf("%d\n",query(,n,l,r,));
}
}
return ;
}
/*
// //
*/
千万不要点
【线段树】HDU 5443 The Water Problem的更多相关文章
- hdu 5443 The Water Problem(长春网络赛——暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java ...
- hdu 5443 The Water Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...
- hdu 5443 The Water Problem 线段树
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU 5443 The Water Problem (ST算法)
题目链接:HDU 5443 Problem Description In Land waterless, water is a very limited resource. People always ...
- ACM学习历程—HDU 5443 The Water Problem(RMQ)(2015长春网赛1007题)
Problem Description In Land waterless, water is a very limited resource. People always fight for the ...
- HDU 5443 The Water Problem (水题,暴力)
题意:给定 n 个数,然后有 q 个询问,问你每个区间的最大值. 析:数据很小,直接暴力即可,不会超时,也可以用RMQ算法. 代码如下: #include <cstdio> #includ ...
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 敌兵布阵(线段树HDU 1166)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
- HDU 5832 A water problem (带坑水题)
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
随机推荐
- Maven Build Life Cycle--reference
What is Build Lifecycle? A Build Lifecycle is a well defined sequence of phases which define the ord ...
- shell脚本中echo显示内容带颜色
转自:http://www.cnblogs.com/lr-ting/archive/2013/02/28/2936792.html shell脚本中echo显示内容带颜色显示,echo显示带颜色,需要 ...
- Java 8 Lambda表达式10个示例【存】
PS:不能完全参考文章的代码,请参考这个文件http://files.cnblogs.com/files/AIThink/Test01.zip 在Java 8之前,如果想将行为传入函数,仅有的选择就是 ...
- CSS3新增UI样式
圆角,border-radius: 1-4个数字/1-4个数字,前面是水平,后面是垂直,不给“/”表示水平和垂直一样,举例如下: <head> <meta http-equiv=&q ...
- JS遍历对象或者数组
一.纯js实现 <script> var obj = {"player_id":"GS001","event_id":" ...
- c# 学习笔记(二)
c#3.0 新特性 扩展方法 扩展方法允许编写和声明它的类之外的关联类的方法 用于没有源代码或者类是密封的,需要给类扩展新方法时 1.扩展方法必须被声明为static2.扩展方法声明所在的类必须被声 ...
- ueditor asp.net版本更改图片保存路径
目的:把本地上传的图片放置到跟目录下的Images/Upload文件夹下. 修改步骤: 1.ueditor.config.js文件中的, imagePath: URL + "net/&quo ...
- ACE的Socket初步
Tcp通信过程一般为如下步骤: 服务器绑定端口,等待客户端连接. 客户端通过服务器的ip和服务器绑定的端口连接服务器. 服务器和客户端通过网络建立一条数据通路,通过这条数据通路进行数据交互. 常用AP ...
- hdu 3371 Connect the Cities (最小生成树Prim)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3371 题目不难 稍微注意一下 要把已经建好的城市之间的花费定义为0,在用普通Prim算法就可以了:我没 ...
- 跟我学android-android常用布局介绍
在上一章我们曾经谈到,Android平台的界面 是使用XML的方式设计的,然后在上一章我们只做了一个简单的界面,在这章,我们将介绍如何使用常用的控件设计实用的界面. Android中的视图都是继承Vi ...