Q个数

问区间最大值-区间最小值

 // #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N=;
const int MOD = 1e9+;
#define LL long long
double const pi = acos(-);
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int a[N];
int Min,Max;
struct Edge{
int l,r;
int minx,maxx;
}e[*N]; void pushup(int rt){
e[rt].minx=min(e[rt<<].minx,e[rt<<|].minx);
e[rt].maxx=max(e[rt<<].maxx,e[rt<<|].maxx);
} void build(int l,int r,int rt){
e[rt].l=l;
e[rt].r=r;
if(l==r){
e[rt].minx=e[rt].maxx=a[l];
return;
}
int mid=(l+r)>>;
build(lson);
build(rson);
pushup(rt);
} void query(int l,int r,int rt,int L,int R){
if(e[rt].maxx<=Max&&e[rt].minx>=Min) return;
if(L<=l&&R>=r){
Min=min(e[rt].minx,Min);
Max=max(e[rt].maxx,Max);
return;
}
int mid=(l+r)>>;
if(L<=mid) query(l,mid,rt<<,L,R);
if(R>mid) query(mid+,r,rt<<|,L,R);
// if(r<=mid) query(lson,L,R);
// else if(l>mid) query(rson,L,R);
// else{
// query(lson,L,R);
// query(rson,L,R);
// }
} int main(){
// fre();
int n,q;
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
build(,n,);
while(q--){
int L,R;
scanf("%d%d",&L,&R);
Min=inf,Max=-inf;
// cout<<"!!"<<endl;
// getch();
query(,n,,L,R);
printf("%d\n",Max-Min);
}
return ;
}

POJ3264 Balanced Lineup 线段树区间最大值 最小值的更多相关文章

  1. BZOJ-1699 Balanced Lineup 线段树区间最大差值

    Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 41548 Accepted: 19514 Cas ...

  2. 【POJ】3264 Balanced Lineup ——线段树 区间最值

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34140   Accepted: 16044 ...

  3. POJ3264 Balanced Lineup —— 线段树单点更新 区间最大最小值

    题目链接:https://vjudge.net/problem/POJ-3264 For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000 ...

  4. poj3264 Balanced Lineup(树状数组)

    题目传送门 Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 64655   Accepted: ...

  5. POJ 3264 Balanced Lineup 线段树 第三题

    Balanced Lineup Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line ...

  6. poj 3264 Balanced Lineup(线段树、RMQ)

    题目链接: http://poj.org/problem?id=3264 思路分析: 典型的区间统计问题,要求求出某段区间中的极值,可以使用线段树求解. 在线段树结点中存储区间中的最小值与最大值:查询 ...

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

  8. POJ 3264 Balanced Lineup 线段树RMQ

    http://poj.org/problem?id=3264 题目大意: 给定N个数,还有Q个询问,求每个询问中给定的区间[a,b]中最大值和最小值之差. 思路: 依旧是线段树水题~ #include ...

  9. nyoj 119 士兵杀敌(三)【线段树区间最大值最小值差】

    士兵杀敌(三) 时间限制:2000 ms  |  内存限制:65535 KB 难度:5   描述 南将军统率着N个士兵,士兵分别编号为1~N,南将军经常爱拿某一段编号内杀敌数最高的人与杀敌数最低的人进 ...

随机推荐

  1. 基于注解风格的Spring-MVC的拦截器

    基于注解风格的Spring-MVC的拦截器 Spring-MVC如何使用拦截器,官方文档只给出了非注解风格的例子.那么基于注解风格如何使用拦截器呢? 基于注解基本上有2个可使用的定义类,分别是Defa ...

  2. [转载]再谈iframe自适应高度

    Demo页面:主页面 iframe_a.html ,被包含页面 iframe_b.htm 和 iframe_c.html 下面开始讲: 通过Google搜索iframe 自适应高度,结果5W多条,搜索 ...

  3. Unity3D调用第三方SDK(之一)从eclipse到Unity3D 友盟

    原地址:http://www.360doc.com/content/14/0120/14/11670799_346638215.shtml 篇展示在Unity3D中调用友盟SDK的实现方法. 首先附上 ...

  4. js获取fck值的代码方法

    引入js文件 <script type="text/javascript" src="${basePath}/FCKeditor/fckeditor.js" ...

  5. Tornado,展示一下模板渲染

    按网上一步一步走一下. 感觉模板和DJANGO的差不多,但更灵活,不限制PYTHON的使用. 前端和后端,这模板使用的规则在哪里呢? import os.path import tornado.htt ...

  6. C++ eof()函数相关应用技巧分享

    C++编程语言中的很多功能在我们的实际应用中起着非常大的作用.比如在对文件文本的操作上,就可以用多种方式来实现.在这里我们介绍的C++ eof()函数就是其中一个比较常用的基本函数. 在使用C/C++ ...

  7. DAO是什么技术

    DAO是Data Access Object数据访问接口,数据访问:故名思义就是与数据库打交道.夹在业务逻辑与数据库资源中间. 在核心J2EE模式中是这样介绍DAO模式的:为了建立一个健壮的J2EE应 ...

  8. jqueryrotate 使用 帮助 笔记 学习

      1.想变角度 $("imgID").rotate(45);   2.想变角度时,有运动过程 $("imgID").rotate({animateTo:45} ...

  9. C#中保留2位小数

    public static void Method() { double a = 1.991; a = Math.Round(a); Console.WriteLine("a = {0}&q ...

  10. JAVA高级特性 - 注解

    注解是插入到代码中用于某种工具处理的标签.这些标签可以在源码层次上进行操作,或者可以处理编译器将其纳入到注解类文件中. 注解不会改变对程序的编译方式.Java编译器会对包含注解和不包含注解的代码生成相 ...