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. mysql 跨库JOIN

    现有两台MYSQL数据库 一台是192.168.1.1 端口3306 上有数据库DB1 有表TABLE1一台是192.168.1.2 端口3307 上有数据库DB2 有表TABLE2192.168.1 ...

  2. 如何在CHROME里调试前端代码?

    以前看前端们调得很神的, 刚看书到这里,作一个记录,演练了一下,确实有点神!!! :) <!DOCTYPE html> <html lang="en"> & ...

  3. jsp关于include html、jsp等文件出现乱码问题的解决方案

    一般来说使用jsp标签<jsp:include>引入一个jsp文件: ①可以在被引入的jsp中加入:<%@ page contentType="text/html;char ...

  4. php简单文件上传类

    <?php header("Content-Type:text/html; charset=utf-8"); if($_POST['submit']){ $upfiles = ...

  5. Qt: 多线程, 就是这么简单(确实非常简洁明了)

    #include <iostream>#include <QApplication>#include <QThread>#include <QString&g ...

  6. Eclipse中查看Android模拟器SD卡目录

    · 有时候用到Android模拟器来模拟SD卡相关操作,在Eclipse中可以直接查看SD卡目录: 首先,新建模拟器的时候要创建SD卡,存储的大小根据需要创建: 启动模拟器,在Eclipse中打开视图 ...

  7. sqlmap批量扫描burpsuite请求日志记录

    sqlmap可以批量扫描包含有request的日志文件,而request日志文件可以通过burpsuite来获取, 因此通过sqlmap结合burpsuite工具,可以更加高效的对应用程序是否存在SQ ...

  8. svn:revert to this version 和 revert changes from this version的区别 假设我们有许多个版本,版本号分别是1-10

    假设我们有许多个版本,版本号分别是1-10 如果我们在7这里选择revert to this version那么7之后的8,9,10的操作都会被消除 如果在7选择revert changes from ...

  9. C++重载输入和输出操作符以及IO标准库中的刷新输入缓冲区残留字符问题

    今天在做C++ Primer习题的14.11时,印象中应该挺简单的一题,结果却费了很长时间. 类定义: typedef string Date; class CheckoutRecord{ publi ...

  10. poj 2965 The Pilots Brothers' refrigerator枚举(bfs+位运算)

    //题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因 ...