http://poj.org/problem?id=3264

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
const int N=;
int dpmin[N][],dpmax[N][];
int main()
{
int i,j,n,m;
scanf("%d%d",&n,&m);
memset(dpmin,,sizeof(dpmin));
memset(dpmax,,sizeof(dpmax));
for(int i=;i<=n;i++){
scanf("%d",&dpmin[i][]);
dpmax[i][]=dpmin[i][];
}
int mm=floor(log(1.0*n)/log(2.0));
for(int j=;j<=mm;j++){
for(int i=;i<=n;i++){
if((i+(<<(j-)))<=n){
dpmin[i][j]=min(dpmin[i][j-],dpmin[i+(<<(j-))][j-]);
dpmax[i][j]=max(dpmax[i][j-],dpmax[i+(<<(j-))][j-]);
}
}
}
int x,y;
for(int i=;i<=m;i++){
scanf("%d%d",&x,&y);
int mid=floor(log(y*1.0-x+)/log(2.0));
int maxnum=max(dpmax[x][mid],dpmax[y-(<<mid)+][mid]);
int minnum=min(dpmin[x][mid],dpmin[y-(<<mid)+][mid]);
printf("%d\n",maxnum-minnum);
}
return ;
}

POJ3264RMQ的更多相关文章

随机推荐

  1. mysql查询表中的所有字段

    select column_name, table_name from information_schema.columns where table_schema='yizhan' and colum ...

  2. jQ的toggle()方法示例

    定义和用法toggle() 方法切换元素的可见状态.如果被选元素可见,则隐藏这些元素,如果被选元素隐藏,则显示这些元素. 语法$(selector).toggle(speed,callback,swi ...

  3. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  4. ulipad 常用快捷键

    快捷键名称 对应功能 F1 (M)UliPad Help Document(帮助文档) F2 (M)Directory Browser(目录浏览)(3.1版新增) F3 (M)Find Next(查找 ...

  5. GL_GL系列 - 会计期间管理分析(案例)

    2014-07-07 Created By BaoXinjian

  6. cf111D Petya and Coloring 组合数学,二项式反演

    http://codeforces.com/contest/111/problem/D Little Petya loves counting. He wants to count the numbe ...

  7. CF 500 C. New Year Book Reading 贪心 简单题

    New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n b ...

  8. poj_2485_mst

     Highways Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit St ...

  9. mysql多表字段名重复的情况

    CREATE TABLE `card` ( `id` ) unsigned NOT NULL AUTO_INCREMENT, `json_str` ) NOT NULL, `f` ,) unsigne ...

  10. vim 学习日志(1):剪切,复制,粘贴,删除,撤销

    一:光标命令     左h 上j 下k 右l :goto n 表示跳转到文本的第n个字符 :n 表示跳到第n行 nG n为行数,该命令立即使光标跳到指定行:n为空,光标跳到文件最后一行. Ctrl+G ...