hdu 5443 (2015长春网赛G题 求区间最值)
求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.=
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
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# include <queue>
# define LL long long
using namespace std ; const int maxn = ; int MAX[maxn<<] ; //结点开4倍 void PushUP(int rt) //更新到父节点
{
MAX[rt] = max(MAX[rt * ] , MAX[rt * + ] ); //rt 为当前结点
} void build(int l , int r , int rt) //构建线段树
{
if (l == r)
{
scanf("%d" , &MAX[rt]) ;
return ;
}
int m = (l + r) / ;
build(l , m , rt * ) ;
build(m + , r , rt * +) ;
PushUP(rt) ;
} int query(int L , int R , int l , int r , int rt) //区间求最大值
{
if (L <= l && r <= R)
return MAX[rt] ;
int m = (l + r) / ;
int ret = ;
if (L <= m)
ret = max(ret , query(L , R , l , m , rt * ) ) ;
if (R > m)
ret = max(ret , query(L , R , m + , r , rt * + ) );
return ret ;
} int main ()
{
//freopen("in.txt","r",stdin) ;
int n , m ;
int T ;
scanf("%d" , &T) ;
while(T--)
{
scanf("%d" , &n) ;
build( , n , ) ;
scanf("%d" , &m) ;
while(m--)
{
int a , b ;
scanf("%d %d" , &a , &b) ;
printf("%d\n", query(a , b , , n , )) ;
}
} return ;
}
hdu 5443 (2015长春网赛G题 求区间最值)的更多相关文章
- 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 ...
- ACM学习历程—HDU 5446 Unknown Treasure(数论)(2015长春网赛1010题)
Problem Description On the way to the next secret treasure hiding place, the mathematician discovere ...
- hdu 5455 (2015沈阳网赛 简单题) Fang Fang
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不 ...
- hihocoder1236(2015长春网赛J题) Scores(bitset && 分块)
题意:给你50000个五维点(a1,a2,a3,a4,a5),50000个询问(q1,q2,q3,q4,q5),问已知点里有多少个点(x1,x2,x3,x4,x5)满足(xi<=qi,i=1,2 ...
- hdu 5446(2015长春网络赛J题 Lucas定理+中国剩余定理)
题意:M=p1*p2*...pk:求C(n,m)%M,pi小于10^5,n,m,M都是小于10^18. pi为质数 M不一定是质数 所以只能用Lucas定理求k次 C(n,m)%Pi最后会得到一个同余 ...
- hdu 5441 Travel (2015长春网赛)
http://acm.hdu.edu.cn/showproblem.php?pid=5441 题目大意是给一个n个城市(点)m条路线(边)的双向的路线图,每条路线有时间值(带权图),然后q个询问,每个 ...
- hdu 5441 (2015长春网络赛E题 带权并查集 )
n个结点,m条边,权值是 从u到v所花的时间 ,每次询问会给一个时间,权值比 询问值小的边就可以走 从u到v 和从v到u算不同的两次 输出有多少种不同的走法(大概是这个意思吧)先把边的权值 从小到大排 ...
- hdu 5003 模拟水题 (2014鞍山网赛G题)
你的一系列得分 先降序排列 再按0.95^(i-1)*ai 这个公式计算你的每一个得分 最后求和 Sample Input12530 478Sample Output984.1000000000 # ...
- hdu 5475 模拟计算器乘除 (2015上海网赛H题 线段树)
给出有多少次操作 和MOD 初始值为1 操作1 y 表示乘上y操作2 y 表示除以第 y次操作乘的那个数 线段树的叶子结点i 表示 第i次操作乘的数 将1替换成y遇到操作2 就把第i个结点的值 替换成 ...
随机推荐
- iOS记录一常用的方法和语句
1.当前控制器是否还显示,比较常用于网络请求回来页面已退出 //当前视图控制器是否在显示 +(BOOL)isCurrentViewControllerVisible:(UIViewController ...
- AJAX 原生态
AJAX 原生态 原生态AJAX详解和jquery对AJAX的封装 A ...
- MySQL5.7安装(RPM)笔记
1. 检查MySQL是否安装,如果有安装,则移除(rpm –e 名称)[root@localhost ~]# rpm -qa | grep -i mysqlmysql-libs-xxxxxxxxxx. ...
- 解析word公式的解决方案(office插入和wps插入不同的解决方案)
这几天在公司的项目有个需求就是数学公式的导入,而对于word来说,插入的公式xml格式,需要转换为mathML,借用插件MathJax来进行展示,而对于wps插入的公式来说,获取到的是一个wmf图片, ...
- 洛谷P4198 楼房重建
题意:给定序列,每次修改一个值,求前缀最大值的个数. 解:线段树经典应用. 每个节点维护最大值和该区间前缀最大值个数. 发现我们不用下传标记,只需要合并区间. 需要实现一个函数int ask([l r ...
- spring注入时报错::No qualifying bean of type 'xxx.xxMapper'
做一个小项目,因为有 baseService,所以偷懒就没有写单独的每个xxService接口,直接写的xxServiceImpl,结果在service实现类中注入Mapper的时候,用的 @Auto ...
- JavaScript基本数据类型介绍
JavaScript基本数据类型介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是javascript JavaScript一种直译式脚本语言,是一种动态类型.弱类型. ...
- bzoj千题计划209:bzoj1185: [HNOI2007]最小矩形覆盖
http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解去看它 http://www.cnblogs.com/TheRoadToTheGold/p ...
- android studio run的时候一直卡在waiting for debug
原因如下: 选择ok就可以,同时我们也可以从这里找到 平常遇到跟真机有关的问题,三步大法,1,插拔手机,2.adb kill-server;adb start-server 3.重启as
- PHP魔术方法之__invoke()
将对象当作函数来使用时,会自动调用该方法. class ShowProfile extends Controller { public function __invoke($id) { return ...