题目链接:

  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的更多相关文章

  1. hdu 5443 The Water Problem(长春网络赛——暴力)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java ...

  2. hdu 5443 The Water Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...

  3. hdu 5443 The Water Problem 线段树

    The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  4. HDU 5443 The Water Problem (ST算法)

    题目链接:HDU 5443 Problem Description In Land waterless, water is a very limited resource. People always ...

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

  6. HDU 5443 The Water Problem (水题,暴力)

    题意:给定 n 个数,然后有 q 个询问,问你每个区间的最大值. 析:数据很小,直接暴力即可,不会超时,也可以用RMQ算法. 代码如下: #include <cstdio> #includ ...

  7. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  8. 敌兵布阵(线段树HDU 1166)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...

  9. HDU 5832 A water problem (带坑水题)

    A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...

随机推荐

  1. [Falcor] Indroduce to Model

    How to work with JSON data indirectly through a Falcor Model. The Falcor Model allows you to work wi ...

  2. Python自动化之5种session类型

    Django中默认支持Session,其内部提供了5种类型的Session供开发者使用: 数据库(默认) 缓存 文件 缓存+数据库 加密cookie 1.数据库Session Django默认支持Se ...

  3. PID38 串的记数(codevs2077)

    /* 假设当前有a个A b个B c个C 用 f[a][b][c]来表示 那么如果这个串以A结尾 那就是 f[a-1][b][c]转移来的 所以构成 f[a][b][c]的串一定有一部分是 f[a-1] ...

  4. java 项目request.getParameter("")接收不到值

    如果发现这个方法 以前能接收到参数,现在不能接收到参数的情况下 很有问题出来tocat 或许jak 的问题上, 换个低版本可能就好了

  5. 【转】Auto Layout 进阶

    原文:http://blog.csdn.net/ysy441088327/article/details/12558097   引言: Auto Layout是iOS6发布后引入的一个全新的布局特性, ...

  6. C#简单一句代码,实现pictureBox的照片另存为磁盘文件不出错

    开发人事档案系统时,一般都要利用pictureBox对人员的照片进行操作,包括选择保存照片.另存照片.删除照片,如下图: 将照片保存到数据库和从数据库中删除,网友写了很多实用代码,非常好用.但是要将p ...

  7. java学习——集合框架(泛型,Map)

    泛型: ... Map:一次添加一对元素.Collection 一次添加一个元素. Map也称为双列集合,Collection集合称为单列集合. 其实map集合中存储的就是键值对. map集合中必须保 ...

  8. linux 命令及进程控制

    main.c  main.o/main.obj  main/main.exe          编译                连接 程序运行;      两步: gcc/g++  -c  mai ...

  9. 【COGS 56】质数取石子

    [问题描述] DD 和 MM 正在玩取石子游戏.他们的游戏规则是这样的:桌上有若干石子,DD 先取,轮流取,每次必须取质数个.如果某一时刻某一方无法从桌上的石子中取质数个,比如说剩下 0 个或 1 个 ...

  10. 【USACO 2.4.3】牛的旅行

    [描述] 农民 John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧区通过任何路径都不连通.这样,Farmer John就有多个 ...