求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.=

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题 求区间最值)的更多相关文章

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

  2. ACM学习历程—HDU 5446 Unknown Treasure(数论)(2015长春网赛1010题)

    Problem Description On the way to the next secret treasure hiding place, the mathematician discovere ...

  3. hdu 5455 (2015沈阳网赛 简单题) Fang Fang

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不 ...

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

  5. 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最后会得到一个同余 ...

  6. hdu 5441 Travel (2015长春网赛)

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 题目大意是给一个n个城市(点)m条路线(边)的双向的路线图,每条路线有时间值(带权图),然后q个询问,每个 ...

  7. hdu 5441 (2015长春网络赛E题 带权并查集 )

    n个结点,m条边,权值是 从u到v所花的时间 ,每次询问会给一个时间,权值比 询问值小的边就可以走 从u到v 和从v到u算不同的两次 输出有多少种不同的走法(大概是这个意思吧)先把边的权值 从小到大排 ...

  8. hdu 5003 模拟水题 (2014鞍山网赛G题)

    你的一系列得分 先降序排列 再按0.95^(i-1)*ai 这个公式计算你的每一个得分 最后求和 Sample Input12530 478Sample Output984.1000000000 # ...

  9. hdu 5475 模拟计算器乘除 (2015上海网赛H题 线段树)

    给出有多少次操作 和MOD 初始值为1 操作1 y 表示乘上y操作2 y 表示除以第 y次操作乘的那个数 线段树的叶子结点i 表示 第i次操作乘的数 将1替换成y遇到操作2 就把第i个结点的值 替换成 ...

随机推荐

  1. 前端学习 -- Css -- 默认样式

    浏览器为了在页面中没有样式时,也可以有一个比较好的显示效果, 所以为很多的元素都设置了一些默认的margin和padding,而它的这些默认样式,正常情况下我们是不需要使用的. 所以我们往往在编写样式 ...

  2. yolo-v2只识别person

    一.修改源代码 (1)修改cfg/voc.data classess=20    改成 classes = 1 (2)修改data/voc.names 只留下person这一类 (3)修改exampl ...

  3. 织梦dedecms搜索页加上序列号autoindex

    在我们做织梦搜索页模板的时候经常会使用到autoindex标签.那么怎么才能实现搜索页可以使用呢?下面给大家分享下解决方法: 打开文件:include/arc.searchview.class.php ...

  4. Flink入门训练--以New York City Taxi为例

    最近在学Flink,准备用Flink搭建一个实时的推荐系统.找到一个好的网站(也算作是flink创始者的官方网站),上面有关于Flink的上手教程,用来练练手,熟悉熟悉,下文仅仅是我的笔记. 1. 数 ...

  5. How To Crawl A Web Page with Scrapy and Python 3

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  6. Linux-Xshell会话保持

    1.Xshell客户端设置 2.服务端设置 修改/etc/ssh/sshd_config文件,找到 ClientAliveInterval 0和ClientAliveCountMax 3并将注释符号( ...

  7. IsNullOrWhiteSpace与IsNullOrEmpty

    public static boolean IsNullOrEmpty(String value) { return (value == null || value.length() == 0);} ...

  8. lua元表详解

    元表的作用 元表是用来定义对table或userdata操作方式的表 举个例子 local t1 = {1} local t2 = {2} local t3 = t1 + t2 我们直接对两个tabl ...

  9. FFmpeg编码扩展之————编码库的扩展(libfdk-aac)

    ffmpeg windows版没有libfdk-acc 请求该地址下载:http://tmod.nmm-hd.org/FFmpeg/

  10. [整]Android SlidingMenu Demo 环境搭建

    1. 下载ActionBarSherlock https://github.com/JakeWharton/ActionBarSherlock 2. 下载SlidingMenu https://git ...