BZOJ1636: [Usaco2007 Jan]Balanced Lineup
1636: [Usaco2007 Jan]Balanced Lineup
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 476 Solved: 345
[Submit][Status]
Description
Input
Output
Sample Input
to a reply and indicates the difference in height between the
tallest and shortest cow in the range.
Sample Output
3
0
HINT
Source
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#define maxn 50000+100
#define maxm 100000
using namespace std;
int n,m,a[maxn],f[maxn][],g[maxn][];
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void rmq()
{
for(int i=;i<=n;i++)f[i][]=a[i];
for(int i=;i<=floor(log(n)/log());i++)
for(int j=;j<=n-(<<i)+;j++)
f[j][i]=max(f[j][i-],f[j+(<<(i-))][i-]);
for(int i=;i<=n;i++)g[i][]=a[i];
for(int i=;i<=floor(log(n)/log());i++)
for(int j=;j<=n-(<<i)+;j++)
g[j][i]=min(g[j][i-],g[j+(<<(i-))][i-]);
}
int query(int x,int y)
{
int z=floor(log(y-x+)/log());
return max(f[x][z],f[y-(<<z)+][z])-min(g[x][z],g[y-(<<z)+][z]);
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
for(int i=;i<=n;i++)a[i]=read();
rmq();
while(m--)
{
int x=read(),y=read();
printf("%d\n",query(x,y));
}
return ;
}
BZOJ1636: [Usaco2007 Jan]Balanced Lineup的更多相关文章
- bzoj1699[Usaco2007 Jan]Balanced Lineup排队*&bzoj1636[Usaco2007 Jan]Balanced Lineup*
bzoj1699[Usaco2007 Jan]Balanced Lineup排队 bzoj1636[Usaco2007 Jan]Balanced Lineup 题意: 询问区间最大值减区间最小值的差. ...
- BZOJ1699: [Usaco2007 Jan]Balanced Lineup排队
1699: [Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 933 Solved: 56 ...
- BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队( RMQ )
RMQ.. ------------------------------------------------------------------------------- #include<cs ...
- BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队
1699: [Usaco2007 Jan]Balanced Lineup排队 Description 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. ...
- bzoj 1636: [Usaco2007 Jan]Balanced Lineup -- 线段树
1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 772 Solved: 560线 ...
- bzoj 1699: [Usaco2007 Jan]Balanced Lineup排队 分块
1699: [Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec Memory Limit: 64 MB Description 每天,农夫 John ...
- [Usaco2007 Jan]Balanced Lineup排队
[Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 2333 Solved: 1424 Des ...
- ST表 || RMQ问题 || BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队 || Luogu P2880 [USACO07JAN]平衡的阵容Balanced Lineup
题面:P2880 [USACO07JAN]平衡的阵容Balanced Lineup 题解: ST表板子 代码: #include<cstdio> #include<cstring&g ...
- 【BZOJ】1636: [Usaco2007 Jan]Balanced Lineup(rmq+树状数组)
http://www.lydsy.com/JudgeOnline/problem.php?id=1636 (我是不会说我看不懂题的) 裸的rmq.. #include <cstdio> # ...
随机推荐
- Configuring Robolectric
There are numerous ways to customize how Robolectric behaves at runtime. Config Annotation The prima ...
- My way to Python - Day05 - 面向对象-思维导图
My way to Python - Day05 - 面向对象 思维导图
- win 10 安装 mysql解压版 步骤
参考资料:win 10 安装 mysql 5.7 网址:http://blog.sina.com.cn/s/blog_5f39af320102wbk0.html 本文参考上面的网址的教程,感谢作者分享 ...
- n进制转为十进制
主程序代码 - #include <stdio.h> #include <string.h> main() { long t1; int i, n, t, t3; ]; pri ...
- Java_Activiti5_菜鸟也来学Activiti5工作流_之入门简单例子(一)
// VacationRequest.java /** * author : 冯孟活 ^_^ * dates : 2015年9月1日 下午10:32:58 * class : 演示简单的公司请假流程 ...
- win2008 64位下.net 无法访问oracle
这两天换了台新机子,就想弄个新系统win2008 64bit来测试下,也尝尝新鲜,结果是碰的头破血流啊,哈哈就像挖宝似的 环境:win2008 64bit + IIS7+.net2.0 +ORACLE ...
- JAVA除去制定字符的方法
只需调用replaceAll()方法: public class Test { public static void main(String[] args) { String s= "abc ...
- 新装的mysql,直接安装板
Windows安装MySQL解压版 http://www.cnblogs.com/xiaoit/p/3932241.html my文件 如下: [mysql]# 设置mysql客户端默认字符集defa ...
- 读懂IL代码(一)
以前刚开始学C#的时候,总有高手跟我说,去了解一下IL代码吧,看懂了你能更加清楚的知道你写出来的代码是如何运行互相调用的,可是那时候没去看,后来补的,其实感觉也不晚.刚开始看IL代码的时候,感觉非常吃 ...
- java SWT/Rap 计算器版本2(键盘鼠标兼容)
package cn.lesaas.nof.rwtswt.ui.dialog; import java.math.BigDecimal; import org.eclipse.swt.SWT;impo ...