Balanced Lineup(线段树)
http://poj.org/problem?id=3264
题意:n个数,q个询问,输出[l,r]中最大值与最小值的差。
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- const int N=;
- struct node
- {
- int l,r;
- int Max,Min;
- } Tree[N*];
- int h[N],max1=,min1=N;
- void build(int l,int r,int rt)
- {
- Tree[rt].l = l;
- Tree[rt].r = r;
- if (l==r)
- {
- Tree[rt].Max=Tree[rt].Min=h[r];
- return ;
- }
- int mid = (l+r)>>;
- build(l,mid,rt<<);
- build(mid+,r,rt<<|);
- Tree[rt].Max=max(Tree[rt<<].Max,Tree[rt<<|].Max);
- Tree[rt].Min=min(Tree[rt<<].Min,Tree[rt<<|].Min);
- }
- void Query(int l,int r,int rt)
- {
- if(Tree[rt].l==l&&Tree[rt].r==r)
- {
- max1=max(max1,Tree[rt].Max);
- min1=min(min1,Tree[rt].Min);
- return ;
- }
- int mid = (Tree[rt].l+Tree[rt].r)>>;
- if (r <= mid)
- Query(l,r,rt<<);
- else if (l > mid)
- Query(l,r,rt<<|);
- else
- {
- Query(l,mid,rt<<);
- Query(mid+,r,rt<<|);
- }
- }
- int main()
- {
- int n,q;
- while(~scanf("%d%d",&n,&q))
- {
- for (int i = ; i <= n; i++)
- scanf("%d",&h[i]);
- build(,n,);
- while(q--)
- {
- max1=-,min1=N;
- int l,r;
- scanf("%d%d",&l,&r);
- Query(l,r,);
- printf("%d\n",max1-min1);
- }
- }
- return ;
- }
Balanced Lineup(线段树)的更多相关文章
- BZOJ-1699 Balanced Lineup 线段树区间最大差值
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 41548 Accepted: 19514 Cas ...
- [POJ] 3264 Balanced Lineup [线段树]
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 34306 Accepted: 16137 ...
- 【POJ】3264 Balanced Lineup ——线段树 区间最值
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 34140 Accepted: 16044 ...
- bzoj 1636: [Usaco2007 Jan]Balanced Lineup -- 线段树
1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 772 Solved: 560线 ...
- POJ 3264 Balanced Lineup 线段树 第三题
Balanced Lineup Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line ...
- poj 3264 Balanced Lineup(线段树、RMQ)
题目链接: http://poj.org/problem?id=3264 思路分析: 典型的区间统计问题,要求求出某段区间中的极值,可以使用线段树求解. 在线段树结点中存储区间中的最小值与最大值:查询 ...
- POJ 3264 Balanced Lineup (线段树)
Balanced Lineup For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the s ...
- POJ 3264 Balanced Lineup 线段树RMQ
http://poj.org/problem?id=3264 题目大意: 给定N个数,还有Q个询问,求每个询问中给定的区间[a,b]中最大值和最小值之差. 思路: 依旧是线段树水题~ #include ...
- POJ3264 Balanced Lineup —— 线段树单点更新 区间最大最小值
题目链接:https://vjudge.net/problem/POJ-3264 For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000 ...
- POJ3264 Balanced Lineup 线段树区间最大值 最小值
Q个数 问区间最大值-区间最小值 // #pragma comment(linker, "/STACK:1024000000,1024000000") #include <i ...
随机推荐
- asp.net mvc,基于aop实现的接口访问统计、接口缓存等
其实asp.net 上aop现有的框架应该蛮多的,比如静态注入式的PostSharp(新版本好像已经商业化了,旧版本又不支持.net4.0+),或者通过反射的(性能会降低). 本文则是通过mvc其中一 ...
- mesh topology for airfoil, wing, blade, turbo
ref Ch. 5, Anderson, CFD the basics with applications numerical grid generation foundations and appl ...
- 数据库中间件MyCat学习总结(1)——MyCat入门简介
为什么需要MyCat? 虽然云计算时代,传统数据库存在着先天性的弊端,但是NoSQL数据库又无法将其替代.如果传统数据易于扩展,可切分,就可以避免单机(单库)的性能缺陷. MyCat的目标就是:低成本 ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 Scores
#1236 : Scores 时间限制:4000ms 单点时限:4000ms 内存限制:256MB 描述 Kyle is a student of Programming Monkey Element ...
- [luoguP3203][HNOI2010]BOUNCE 弹飞绵羊(LCT)
传送门 每个点都会跳到另一个点,连边就是一棵树. 更改弹力就是换边. 求一个点跳多少次跳到终点就是求这个点的深度,那么只需要维护 size 域,access(n + 1) 然后 splay(x),求 ...
- Promise 异步编程
//1.解决异步回调问题 //1.1 如何同步异步请求 //如果几个异步操作之间并没有前后顺序之分,但需要等多个异步操作都完成后才能执行后续的任务,无法实现并行节约时间 const fs = requ ...
- 复习1背包dp
背包问题是对于一个有限制的容器,一般计算可以装的物品的价值最值或数量.通常每个物品都有两个属性空间和价值,有时还有数量或别的限制条件,这个因体而异. 背包大概分成3部分,下面会细述这最经典的3种题型 ...
- nyoj_528_找球号(三)_201404152050
找球号(三) 时间限制:2000 ms | 内存限制:3000 KB 难度:2 描述 xiaod现在正在某个球场负责网球的管理工作.为了方便管理,他把每个球都编了号,且每个编号的球的总个数都是 ...
- Java使用JNA调用DLL库
Java调用DLL方法有三种,JNI.JNA.JNative, 本文为JNA JNA为使用jna.jar包,下载地址:http://www.java2s.com/Code/Jar/j/Download ...
- 超简单的vue2.0分页组件
1.组件代码 <template> <div class="pagination_comment_style" style="width: 100%;o ...