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

求区间内最大的水源,之前区间dp没法做,会T,用rmq

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
//#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e3+10;
int a[N],MAX[N][20];
void first(int n)
{
for(int j=1;(1<<j)<=n;j++)
{
for(int i=1;i+(1<<j)-1<=n;i++)
{
MAX[i][j]=max(MAX[i][j-1],MAX[i+(1<<(j-1))][j-1]);
//MIN[i][j]=min(MIN[i][j-1],MIN[i+(1<<(j-1))][j-1];
}
}
}
int solve(int l,int r)
{
int x=0;
while(l-1+(1<<x)<=r) x++;
x--;
return max(MAX[l][x],MAX[r-(1<<x)+1][x]);
}
int main()
{
int re,n,tot,l,r;scf(re);
while(re--)
{
mm(a,0);
mm(MAX,0);
scf(n);
rep(i,1,n+1)
{
scf(a[i]);
MAX[i][0]=a[i];
}
first(n);
scf(tot);
while(tot--)
{
scff(l,r);
prf(solve(l,r));
}
}
return 0;
}

A - The Water Problem的更多相关文章

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

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

  2. hdu5832 A water problem

    A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  3. hdu 5443 The Water Problem

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

  4. HDU 5867 Water problem (模拟)

    Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...

  5. HDU 5832 A water problem

    A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

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

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

  7. hdu 5443 The Water Problem 线段树

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

  8. HDU-4974 A simple water problem

    http://acm.hdu.edu.cn/showproblem.php?pid=4974 话说是签到题,我也不懂什么是签到题. A simple water problem Time Limit: ...

  9. The Water Problem(排序)

    The Water Problem Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  10. HDU 4974 A simple water problem(贪心)

    HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...

随机推荐

  1. openstack之Neutron网络模式vlan,gre,vxlan详解

    第一:neutron openvswitch + vlan虚拟网络 一:基础知识 vlan基础知识 1.vlan介绍 1.1:首先说下lan,LAN 表示 Local Area Network,本地局 ...

  2. openstack 之~openstack各组件关系

    认识openstack 第一:openstack是什么? OpenStack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache许可证授权的自由软件和开放源代码项 ...

  3. spring中的多线程aop方法拦截

    日常开发中,常用spring的aop机制来拦截方法,记点日志.执行结果.方法执行时间啥的,很是方便,比如下面这样:(以spring-boot项目为例) 一.先定义一个Aspect import org ...

  4. ESP8266 NOOS SDK libat.a Functions

    at_baseCmd.o custom_infoat_baseCmd.o at_exeCmdNullat_baseCmd.o at_setupCmdEat_baseCmd.o at_exeCmdRst ...

  5. 一步步教你轻松学支持向量机SVM算法之案例篇2

    一步步教你轻松学支持向量机SVM算法之案例篇2 (白宁超 2018年10月22日10:09:07) 摘要:支持向量机即SVM(Support Vector Machine) ,是一种监督学习算法,属于 ...

  6. SpUtil多样加密存储,兼容android9.0

    代码地址如下:http://www.demodashi.com/demo/15058.html 前言 在android系统不断升级的过程中,Sharepreferences存储出现多中问题,其中有些是 ...

  7. Centos升级mongo客户端

    一.背景 在宿主机centos上启一个Mongo容器,暴露端口21117,并设置用户名,密码(root/mongo) docker run --name mongo1 -p : -d mongo -- ...

  8. 这些APP开发技巧可少花60万!

    用户需求——我偏不用干嘛要装? 随着手机的普及,大众流量的端口从电脑转移到手机,传统的商业平台从线下到电脑再到手机进行了转换.手机APP作为移动互联网的入口,众多创业者凭借一个手机APP成就了亿万财富 ...

  9. 【Python】 解析Python中的运算符

    Python中的运算符相比较于传统的C/C++差别不是很大,主要是一些个别的运算符上的差别.包括:算术.比较.赋值.位.逻辑.成员.身份等.它们的优先级: 符号 说明 ** 指数(最高优先级) ~,+ ...

  10. SNF框架及机器人2018年1-9月份升级内容

    1月 增加评星控件.年月选择控件 完善表格弹框的封装,增加多选弹框 的封装 增加表格 单元格合并.列头必填与可填写的标识 4月 关于分页查询和排序的各种修改(扶额) 导入excel优化 bs计算合计的 ...