ACM学习历程—HDU 5443 The Water Problem(RMQ)(2015长春网赛1007题)
题目大意就是给定区间,求区间最值。
这里采用了RMQ的ST算法,直接套的模板。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> using namespace std; const int maxN = ;
int n, q;
int a[maxN];
int ma[maxN][]; void RMQ()
{
memset(ma, , sizeof(ma));
for (int i = ; i < n; ++i)
ma[i][] = a[i];
for (int j = ; (<<j) <= n; ++j)
for (int i = ; i+(<<j)- < n; ++i)
ma[i][j] = max(ma[i][j-], ma[i+(<<(j-))][j-]);
} int query(int lt, int rt)
{
int k = ;
while ((<<(k+)) <= rt-lt+)
k++;
return max(ma[lt][k], ma[rt-(<<k)+][k]);
} void input()
{
scanf("%d", &n);
for (int i = ; i < n; ++i)
scanf("%d", &a[i]);
RMQ();
} void work()
{
scanf("%d", &q);
int u, v, ans;
for (int i = ; i < q; ++i)
{
scanf("%d%d", &u, &v);
ans = query(u-, v-);
printf("%d\n", ans);
}
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times < T; ++times)
{
input();
work();
}
return ;
}
ACM学习历程—HDU 5443 The Water Problem(RMQ)(2015长春网赛1007题)的更多相关文章
- ACM学习历程—HDU 5446 Unknown Treasure(数论)(2015长春网赛1010题)
Problem Description On the way to the next secret treasure hiding place, the mathematician discovere ...
- ACM学习历程—HDU 5025 Saving Tang Monk(广州赛区网赛)(bfs)
Problem Description <Journey to the West>(also <Monkey>) is one of the Four Great Classi ...
- ACM学习历程——HDU5017 Ellipsoid(模拟退火)(2014西安网赛K题)
---恢复内容开始--- Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distanc ...
- ACM学习历程—HDU 5289 Assignment(线段树 || RMQ || 单调队列)
Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fro ...
- hdu 5443 (2015长春网赛G题 求区间最值)
求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.= Sample Input3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 2 ...
- hdu 5475 模拟计算器乘除 (2015上海网赛H题 线段树)
给出有多少次操作 和MOD 初始值为1 操作1 y 表示乘上y操作2 y 表示除以第 y次操作乘的那个数 线段树的叶子结点i 表示 第i次操作乘的数 将1替换成y遇到操作2 就把第i个结点的值 替换成 ...
- hdu 5443 The Water Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...
- hdu 5443 The Water Problem(长春网络赛——暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java ...
- hdu 5443 The Water Problem 线段树
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
随机推荐
- 在VS中自动生成NuGet包以及搭建自己的或单位内部的NuGet服务器
关于NuGet的介绍已经很多,可以参考下面的: NuGet学习笔记(1)--初识NuGet及快速安装使用 http://kb.cnblogs.com/page/143190/ NuGet学习笔记(2) ...
- poj1066(叉乘的简单应用)
做完了才发现,好像没有人和我的做法一样的,不过我怎么都觉得我的做法还是挺容易想的. 我的做法是: 把周围的方框按顺时针编号,然后对于每一条边,如果点出现在边的一侧,则把另一侧所有的点加1,这样最后统计 ...
- 记录-springMVC访问web-inf下文件问题+在jsp页面导入jquery插件路径不对问题
环境:spring + springMvc + mybatis + maven 关于在springMVC环境访问web-inf目录下文件,其一有在springMVC xml文件下加 <!-- 对 ...
- swift打印方法名文件路径
1.打印方法名 print(#function) 1.打印文件路径 print(#file)
- UITableView 右侧索引
1.设置右侧索引字体颜色 self.tabView.sectionIndexColor = [UIColor blackColor]; 2.设置右侧索引背景色 self.cityTabView.sec ...
- iOS9 3D Touch使用
http://www.cnblogs.com/zhanglinfeng/p/5133939.html
- 洛谷 P1558 色板游戏
洛谷 题解里面好像都是压位什么的, 身为蒟蒻的我真的不会, 所以就来谈谈我的30颗线段树蠢方法吧! 这题初看没有头绪. 然后发现颜色范围好像只有30: 所以,我就想到一种\(sao\)操作,搞30颗线 ...
- IntelliJ IDEA(2017)安装和破解(转发)
IntelliJ IDEA(2017)安装和破解 IDEA 全称 IntelliJ IDEA,是Java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一,尤其在智能代码助手 ...
- linux shell 中数组使用方法介绍
linux shell在编程方面比windows 批处理强大太多,不管是在循环.运算.已经数据类型方面都是不能比較的. 以下是个人在使用时候,对它在数组方面一些操作进行的总结. 1.数组定义 [che ...
- (转)Spring 缓存EhCacheFactoryBean
Spring使用Cache 从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我 ...