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个结点的值 替换成 ...
随机推荐
- [代码]--c#获取系统时间
public DateTime GetServerDataTime() { string sql = " select top 1 getdate() from sysobjects &qu ...
- Java 8新特性之lambda(八恶人-2)
Major Marquis Warren 沃伦·马奎斯少校 “Tring to get a couple of bounties in to Red Rock.”我想带几个通缉犯去红石镇 一.基本介绍 ...
- 51nod 1206 && hdu 1828 Picture (扫描线+离散化+线段树 矩阵周长并)
1206 Picture 题目来源: IOI 1998 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注 给出平面上的N个矩形(矩形的边平行于X轴 ...
- 【BZOJ2257】[JSOI2009]瓶子和燃料(数论)
[BZOJ2257][JSOI2009]瓶子和燃料(数论) 题面 BZOJ 洛谷 题解 很明显就是从\(n\)个数里面选\(K\)个数让他们的\(gcd\)最大. 暴力找所有数的因数,拿个什么东西存一 ...
- BZOJ 3195 [Jxoi2012]奇怪的道路 | 状压DP
传送门 BZOJ 3195 题解 这是一道画风正常的状压DP题. 可以想到,\(dp[i][j][k]\)表示到第\(i\)个点.已经连了\(j\)条边,当前\([i - K, i]\)区间内的点的度 ...
- Winform Treeview 排序及图标处理
一.排序 1. 继承 IComparer 2. treeView1.TreeViewNodeSorter = this; 3. 实现IComparer public int Compare(ob ...
- excel根据一列关键字将多个表格中所需列合并
VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]) lookup_value要查询的列 table_array第一列是被 ...
- Tomcat权威指南-读书摘要系列10
Tomcat集群 一些集群技术 DNS请求分配 TCP网络地址转换请求分配 Mod_proxy_balance负载均衡与故障复原 JDBC请求分布与故障复原
- Hadoop生态圈-Flume的组件之拦截器与选择器
Hadoop生态圈-Flume的组件之拦截器与选择器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客只是配置的是Flume主流的Interceptors,想要了解更详细 ...
- python学习笔记5--加密模块hashlib
import hashlib # md5 ybm_pwd='yuanbapqingsdfs234FF234HF@F' # m = hashlib.md5() # bytes_ybq = ybm_pwd ...