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的更多相关文章

  1. 1126. Magnetic Storms(单调队列)

    1126 最简单的单调队列应用吧 单调队列是指在一个队列中各个元素单调 递增(或者递减),并且各个元素的下标单调 递增. 单调队列的大体操作 进队时,将进队的元素为e,从队尾往前扫描,直到找到一个不大 ...

  2. ural1126 Magnetic Storms

    Magnetic Storms Time limit: 0.5 secondMemory limit: 64 MB The directory of our kindergarten decided ...

  3. Magnetic Storms

    http://acm.timus.ru/problem.aspx?space=1&num=1126 简单的线段树求区间最值 #include <stdio.h> #include ...

  4. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  5. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  6. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  7. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  8. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  9. 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 ...

随机推荐

  1. linux下服务器管理

    0.更新国内yum源,参考:http://blog.csdn.net/zhaoyue007101/article/details/8456188 1.创建用户.用户组: 新增用户组 groupadd ...

  2. Fork 一个仓库并同步

    Fork 一个示例仓库 Fork 是对一个仓库的克隆.克隆一个仓库允许你自由试验各种改变,而不影响原始的项目. 一般来说,forks 被用于去更改别人的项目(贡献代码给已经开源的项目)或者使用别人的项 ...

  3. Linux操作系统以及各大发行版介绍——Linux operating system and major distribution is introduced

    什么是Linux? 也许很多人会不屑的说,Linux不就是个操作系统么.错!Linux不是一个操作系统,严格来讲,Linux只是一个操作系统中的内核.内核是什么?内核建立了计算机软件与硬件之间通讯的平 ...

  4. 港股street和nominee区别

    股票的street和nominee区别主要用在公司行动的过户费方面,street股票需要收取过户费,nominee不收过户费. street股票通过做公司行动收取过户费后会变成nominee股票,下次 ...

  5. WebLogic简单的备份和恢复

    万一发生故障,为了迁移或者恢复WebLogic域,应定期地备份管理服务器机器上的整个域目录树.这样,只需恢复域目录并重启管理服务器就可以使服务器从硬件或者系统故障中恢复.在WebLogic生产域中,需 ...

  6. java—— 文件操作

    目录: 1.博文链接 2. 1.博文链接 向文件未追加内容:流操作通过BufferedWriter向文件末尾追加内容的几种常用方法

  7. [Angular 2] Child Router

    Benefit to use child router is Angualr 2 then can lazy load the component on demand. Define a child ...

  8. 使用 Spring 2.5 基于注解驱动的 Spring MVC--转

    概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...

  9. 二叉排序树BST代码(JAVA)

        publicclassTest{     publicstaticvoid main(String[] args){         int[] r =newint[]{5,1,3,4,6,7 ...

  10. 关于飞控下载时候出现avrdude: stk500_getsync(): not in sync: resp=0x00错误的解决方法

    avrdude: stk500_getsync(): not in sync: resp=0x00该问题表述为串口通信失败 经过分析,出现这种情况的原因大致有:1.arduino在IDE下载过程中没有 ...