POJ 3264 Balanced Lineup(ST模板)
链接:http://poj.org/problem?id=3264
题意:给n个数,求一段区间L,R的最大值 - 最小值,Q次询问
思路:ST表模板,预处理区间最值,O(1)复杂度询问
AC代码:
#include<iostream>
#include<vector>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = ;
const int logn = ;
int Log[maxn];
int MIN[maxn][logn];
int MAX[maxn][logn];
int cow[maxn];
int n,q;
void pre(){
Log[] = ;
Log[] = ;
for(int i = ;i<=n;i++){
Log[i] = Log[i/] + ;
}
}
void st(){
for(int i = ;i<=n;i++){
MIN[i][] = MAX[i][] = cow[i];
}
for(int j = ;(<<j)<=n;j++){
for(int i = ;i+(<<j)-<=n;i++){
MAX[i][j] = max(MAX[i][j-],MAX[i+(<<(j-))][j-]);
MIN[i][j] = min(MIN[i][j-],MIN[i+(<<(j-))][j-]);
}
}
}
int main()
{
scanf("%d%d",&n,&q);
for(int i = ;i<=n;i++){
scanf("%d",&cow[i]);
}
pre();
st();
while(q--){
int A,B;
scanf("%d%d",&A,&B);
int s = Log[B-A+];
int range_max = max(MAX[A][s],MAX[B-(<<s)+][s]);
int range_min = min(MIN[A][s],MIN[B-(<<s)+][s]);
cout<<range_max-range_min<<endl;
}
return ;
}
POJ 3264 Balanced Lineup(ST模板)的更多相关文章
- Poj 3264 Balanced Lineup RMQ模板
题目链接: Poj 3264 Balanced Lineup 题目描述: 给出一个n个数的序列,有q个查询,每次查询区间[l, r]内的最大值与最小值的绝对值. 解题思路: 很模板的RMQ模板题,在这 ...
- [POJ] 3264 Balanced Lineup [ST算法]
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 34306 Accepted: 16137 ...
- POJ 3264 Balanced Lineup(模板题)【RMQ】
<题目链接> 题目大意: 给定一段序列,进行q次询问,输出每次询问区间的最大值与最小值之差. 解题分析: RMQ模板题,用ST表求解,ST表用了倍增的原理. #include <cs ...
- POJ 3264 Balanced Lineup | st表
题意: 求区间max-min st表模板 #include<cstdio> #include<algorithm> #include<cstring> #inclu ...
- POJ 3264 Balanced Lineup 【ST表 静态RMQ】
传送门:http://poj.org/problem?id=3264 Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total S ...
- poj 3264 Balanced Lineup【RMQ-ST查询区间最大最小值之差 +模板应用】
题目地址:http://poj.org/problem?id=3264 Sample Input 6 3 1 7 3 4 2 5 1 5 4 6 2 2 Sample Output 6 3 0分析:标 ...
- poj 3264 Balanced Lineup 题解
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Subm ...
- poj 3264 Balanced Lineup (RMQ)
/******************************************************* 题目: Balanced Lineup(poj 3264) 链接: http://po ...
- POJ 3264 Balanced Lineup【线段树区间查询求最大值和最小值】
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 53703 Accepted: 25237 ...
- POJ - 3264——Balanced Lineup(入门线段树)
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 68466 Accepted: 31752 ...
随机推荐
- Balanced Lineup POJ - 3264
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
- Chapter2二分与前缀和
Chapter 2 二分与前缀和 +++ 二分 套路 如果更新方式写的是R = mid, 则不用做任何处理,如果更新方式写的是L = mid,则需要在计算mid是加上1. 1.数的范围 789 #in ...
- javaSE学习笔记(11)--- Map
javaSE学习笔记(11)--- Map 1.Map集合 现实生活中,我们常会看到这样的一种集合:IP地址与主机名,身份证号与个人,系统用户名与系统用户对象等,这种一一对应的关系,就叫做映射.Jav ...
- HDU1862 - EXCEL排序
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1862 解题思路:结构体排序 #include <bits/stdc++.h> using ...
- Google Chrome 退出清除浏览数据
版本 79.0.3945.88(正式版本) (64 位) 设置-高级-隐私设置和安全性-网站设置-Cookie和网站数据-退出Chrome时清除Cookie及网站数据.
- jquery赋值
$("#test1").text("Hello world!"); $("#test2").html("<b>Hell ...
- Python面向对象三大特性(封装、继承、多态)
封装 类中把某些属性和方法隐藏起来,或者定义为私有,只在类的内部使用,在类的外部无法访问,或者留下少量的接口(函数)供外部访问:从上一篇文章中的私有属性与私有方法中的代码体现了该特性. class m ...
- Pi和e的积分
Evaluate integral $$\int_{0}^{1}{x^{-x}(1-x)^{x-1}\sin{\pi x}dx}$$ Well,I think we have $$\int_{0}^{ ...
- 2020牛客寒假算法基础集训营1 F-maki和tree
链接:https://ac.nowcoder.com/acm/contest/3002/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- swagger文档使用
https://www.cnblogs.com/suizhikuo/p/9397417.html