A - The Water Problem
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的更多相关文章
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu5832 A water problem
A water problem Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 5443 The Water Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...
- HDU 5867 Water problem (模拟)
Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...
- HDU 5832 A water problem
A water problem Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5832 A water problem (带坑水题)
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
- hdu 5443 The Water Problem 线段树
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU-4974 A simple water problem
http://acm.hdu.edu.cn/showproblem.php?pid=4974 话说是签到题,我也不懂什么是签到题. A simple water problem Time Limit: ...
- The Water Problem(排序)
The Water Problem Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDU 4974 A simple water problem(贪心)
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
随机推荐
- 表型数据(Phenotype Data)基本概念
表型(英语:Phenotype),又称表现型,对于一个生物而言,表示它某一特定的物理外观或成分.一个人是否有耳珠.植物的高度.人的血型.蛾的颜色等等,都是表型的例子. 表型主要受生物的基因型和环境影响 ...
- leetcode 566. 重塑矩阵 c++ 实现
1.问题描述: 在MATLAB中,有一个非常有用的函数 reshape,它可以将一个矩阵重塑为另一个大小不同的新矩阵,但保留其原始数据. 给出一个由二维数组表示的矩阵,以及两个正整数r和c,分别表示想 ...
- (20170207)开源第三方学习之JSONModel
1:仓库地址:https://github.com/jsonmodel/jsonmodel 主要作用是把JSON字符串转成Model实体,也可以把实体转化成JSON字符串:还包含一些转字典的内容: ...
- 移动端禁止页面拖动 h5禁止拖动页面
PC上css控制滚动仅css("overflow","hidden")已足够. 但是,如果在Mobile上还是可以拖动的!所以需要监听touchmove事件. ...
- SNF软件开发机器人-子系统-功能-启用大按钮样式如何配置
启用大按钮 当启用大按钮被选中后,页面的按钮图表将以按钮配置中的大按钮样式显示. 1.效果展示: 2.使用说明: 打开显示页面,点击开发者选项的简单配置按钮.在功能表信息中选择启用大按钮复选框后保存.
- NameError:name ‘xrange’ is not defined
运行某代码时,报错: NameError:name 'xrange' is not defined 原因: 在Python 3中,range()与xrange()合并为range( ).我的pytho ...
- JSON.stringify转化报错
两种方式会导致该错误:1.json格式数据存在循环调用. 举个例子: var obj = { title: '标题'}obj.content = obj;JSON.stringify(obj); ...
- Super expression must either be null or a function, not undefined
按照之前买的用JavaScript开发移动应用的例子来编写的,然后报了这个错.我的头部声明是这样的 var React = require('react-native'); var { Text, V ...
- [转]Mybatis foreach 批量操作
原文地址:https://blog.csdn.net/jason5186/article/details/40896043 foreach属性属性 描述item 循环体中的具体对象.支持属 ...
- 【iCore4 双核心板_ARM】例程三十二:UART_IAP_ARM实验——更新升级STM32
实验现象及操作说明: 1.本例程共有两个代码包,APP和IAP,IAP程序功能实现将APP程序升级至STM32中. 2.直接上电或烧写程序将执行升级的APP应用程序. BIN升级文件产生方法: 1.编 ...