Magnetic Storms
http://acm.timus.ru/problem.aspx?space=1&num=1126
简单的线段树求区间最值
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=;
int a[N],ans ;
struct node
{
int l,r,Max;
} tree[N*];
void build(int t,int l,int r)
{
tree[t].l = l;
tree[t].r = r;
if (l==r)
{
tree[t].Max = a[r];
return ;
}
int mid = (l+r)>>;
build(t<<,l,mid);
build(t<<|,mid+,r);
tree[t].Max = max(tree[t<<].Max,tree[t<<|].Max);
}
void Query(int t,int l,int r)
{
if (l <= tree[t].l && r>= tree[t].r)
{
ans = max(ans,tree[t].Max);
return ;
}
int mid = (tree[t].l+tree[t].r)>>;
if (r <= mid)
Query(t<<,l,r);
else if (l > mid)
Query(t<<|,l,r);
else
{
Query(t<<,l,mid);
Query(t<<|,mid+,r);
}
}
int main()
{
int m,n = ,x;
scanf("%d",&m);
while()
{
scanf("%d",&x);
if (x == -)
break;
a[n++] = x;
}
build(,,n);
for (int i = ; i <= n-m; i++)
{
ans = ;
Query(,i,m+i-);
printf("%d\n",ans);
}
return ;
}
Magnetic Storms的更多相关文章
- ural1126 Magnetic Storms
Magnetic Storms Time limit: 0.5 secondMemory limit: 64 MB The directory of our kindergarten decided ...
- 1126. Magnetic Storms(单调队列)
1126 最简单的单调队列应用吧 单调队列是指在一个队列中各个元素单调 递增(或者递减),并且各个元素的下标单调 递增. 单调队列的大体操作 进队时,将进队的元素为e,从队尾往前扫描,直到找到一个不大 ...
- ural 1126 Magnetic Storms
http://acm.timus.ru/problem.aspx?space=1&num=1126 #include <cstdio> #include <cstring&g ...
- NOTES : A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung
NOTES : A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung 背景知识: Ga ...
- Transcranial magnetic stimulation (TMS)
Transcranial magnetic stimulation (TMS) Effect of Transcranial Magnetic Stimulation on Free Will Tra ...
- MaLoc: a practical magnetic fingerprinting approach to indoor localization using smartphones
https://www.indooratlas.com/ MaLoc: a practical magnetic fingerprinting approach to indoor localizat ...
- Magnetic Fingerprinting Approach to Indoor Localization
Magnetic Fingerprinting Approach to Indoor Localization
- HearthBuddy Magnetic 磁力
https://hearthstone.gamepedia.com/Magnetic Magnetic is an ability exclusive to certain Mech minions ...
- LA 4064 Magnetic Train Tracks
题意:给定平面上$n(3\leq n \leq 1200)$个无三点共线的点,问这些点组成了多少个锐角三角形. 分析:显然任意三点可构成三角形,而锐角三角形不如直角或钝角三角形容易计数,因为后者有且仅 ...
随机推荐
- Spring 中无处不在的 Properties
转自:https://javadoop.com/post/spring-properties?hmsr=toutiao.io&utm_medium=toutiao.io&utm_sou ...
- 关闭的连接: next
1.最近做了一个项目,扫描读取了第三方数据库的数据,结果本来在公司测试没有问题的程序在客户那边一直报如下错误: java.sql.SQLException: 关闭的连接: next 代码如下: //第 ...
- slf4j-api、slf4j-log4j12、log4j的关系
在网上找到一篇关于这三个jar包的关系的博客,讲的很好,所以就转载了: https://blog.csdn.net/tengdazhang770960436/article/details/18006 ...
- APUE 文件和目录
文件和目录 Unix 所有的文件都对应一个 struct stat,包含了一个文件所有的信息. #include <sys/stat.h> struct stat { mode_t st_ ...
- scrapy 按顺序抓取text内容
需求:获得如下li.clearfix 下的所有text,并且按顺序输出 1. x.css('div.reply-doc h4 a::text').extract(); 2. x.css('div.r ...
- Network----轮询
轮询: 定时每隔多长时间刷新一次,但是,7X24的对服务器的压力会过大,因为在夜间或者是流量低峰期时,他还要持续工作. 客户端发一次请求,服务器就要相应一次. 长轮询: 和轮询的模式不同,长轮询是一次 ...
- 热词解析(9) — hangry
今天给大家介绍一个非常有趣.又超级实用的词!!中文叫"饿极而怒",英文叫... 不知道你有没有这样的经历,当你饿着肚子等着你妈做饭,结果你妈却在麻将桌上不下来,你就越来越饿,越饿越 ...
- 06 Python流程控制
目录: 12) if语句 13) 三目运算 14) while语句 15) break与continue关键字 16) while…else语句 12,if语句 Note: 在一个if语 ...
- MyBatis 3判断不为null
<if test="type!=null and type!=''"> AND type = #{type} </if>
- 使用SwipeRefreshLayout和RecyclerView实现仿“简书”下拉刷新和上拉载入很多其它
一.概述 本篇博客介绍的是怎样使用SwipeRefreshLayout和RecyclerView实现高仿简书Android端的下拉刷新和上拉载入很多其它的效果. 依据效果图能够发现,本案例实现了例如以 ...