ural 1126 Magnetic Storms
http://acm.timus.ru/problem.aspx?space=1&num=1126
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 25500
using namespace std; int a[maxn];
struct node
{
int l,r;
int max1;
}tree[maxn*];
int max2; void build(int i,int l,int r)
{
tree[i].l=l;tree[i].r=r;
if(l==r)
{
tree[i].max1=a[l];
return ;
}
int mid=(l+r)>>;
build(i<<,l,mid);
build(i<<|,mid+,r);
tree[i].max1=max(tree[i<<].max1,tree[i<<|].max1);
} void search1(int i,int l,int r)
{
if(tree[i].l==l&&tree[i].r==r)
{
max2=max(max2,tree[i].max1);
return ;
}
int mid=(tree[i].l+tree[i].r)>>;
if(r<=mid)
{
search1(i<<,l,r);
}
else if(l>mid)
{
search1(i<<|,l,r);
}
else
{
search1(i<<,l,mid);
search1(i<<|,mid+,r);
}
} int main()
{
int m,c;
scanf("%d",&m);
int n=;
while()
{
scanf("%d",&c);
if(c==-) break;
a[n++]=c;
}
build(,,n);
for(int i=; i<n-m+; i++)
{
max2=-;
search1(,i,i+m-);
printf("%d\n",max2);
}
return ;
}
ural 1126 Magnetic Storms的更多相关文章
- 1126. Magnetic Storms(单调队列)
1126 最简单的单调队列应用吧 单调队列是指在一个队列中各个元素单调 递增(或者递减),并且各个元素的下标单调 递增. 单调队列的大体操作 进队时,将进队的元素为e,从队尾往前扫描,直到找到一个不大 ...
- ural1126 Magnetic Storms
Magnetic Storms Time limit: 0.5 secondMemory limit: 64 MB The directory of our kindergarten decided ...
- Magnetic Storms
http://acm.timus.ru/problem.aspx?space=1&num=1126 简单的线段树求区间最值 #include <stdio.h> #include ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
随机推荐
- 1000 A+B [ACM刷题]
这一段时间一直都在刷OJ,这里建一个博客合集,用以记录和分享算法学习的进程. github传送门:https://github.com/haoyuanliu/Online_Judge/tree/mas ...
- C++读写文件并排序
比如一条记录是 1987 9 2 1988 8 26 代表公司员工生日 然后需要读入到系统 现在需要放入容器,并且排序 最后输出到新的文件中,按照年龄由大到小. #include "stda ...
- unity3d触屏操作对象运动
using UnityEngine; using System.Collections; public class robot : MonoBehaviour { private GameObject ...
- REMOTE HOST IDENTIFICATION HAS CHANGED
今天在使用scp命令上传文件到远端服务器时报如下错误,(ssh命令连接到远程服务器时也报同样的错误): @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...
- NYOJ-569最大公约数之和
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=569 此题目可以用筛选法的思想来做,但是用到一个欧拉函数 gcd(1,12)=1,gcd( ...
- divmod(a,b)函数
python每日一函数 - divmod数字处理函数 divmod(a,b)函数 中文说明: divmod(a,b)方法返回的是a//b(除法取整)以及a对b的余数 返回结果类型为tuple 参数: ...
- hdu 1869
题意是给m组人物关系,然后判断是否符合六度分离,代码主要就是三个for那里 然后要记得后面判断的时候是大于7,这题除了Florde算法,还有另外一种算法,不过我没记.... #include < ...
- SQL Server 2008将数据导出为脚本
之前我们要将一个表中的数据导出为脚本,那么只有在网上找一个导出数据的Script,然后运行就可以导出数据脚本了.现在在SQL Server 2008的Management Studio中增加了一个新特 ...
- java BigDecimal的操作
今天给大家讲一下java中BigDecimal的操作.由于double,float的精度不够,因此在进行商业计算的时候要使用的BigDecimal.BigDecimal对象创建如下: BigDecim ...
- IOS开发,如何用最新的Itunes给手机装ipa文件
搜了半天,发现网上的很多教“使用Itunes给手机装ipa文件”文字都好几年了,现在的Itunes跟过去几年的功能和界面都有很大改变,话不多说直接两句话讲明白,希望帮到需要的人. 使用Itunes给手 ...