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. poj1190 生日蛋糕 dfs

    题意:生日蛋糕有m层,总体积是V.从下向上,每一层的半径r和高度h都是递减的. 给m.v,求最小的表面积s.(不算底面接地的面积) 题目链接:poj1190 剪枝都还没加..样例输出都是错的...还没 ...

  2. AFNetworking (3.1.0) 源码解析 <五>

    这次主要开始讲解一下文件夹Serialization下的类AFURLRequestSerialization. AFURLRequestSerialization类遵守`AFURLRequestSer ...

  3. swift学习资料初探

    1.  http://code.csdn.net/news/2820075

  4. [Redux] Implementing Store from Scratch

    Learn how to build a reasonable approximation of the Redux Store in 20 lines. No magic! const counte ...

  5. html表格合并(行,一排)

    <table> <tr> <td colspan="2">失败的例子:</td> </tr> {% for ip , j ...

  6. rman catalog (rman 恢复目录)

    受控制文件大小的限制,一般rman需要用rman catalog来管理及存放备份信息: 这里介绍一下创建rman catalog的步骤: C:\Documents andSettings\Admini ...

  7. 小学生之深入C#

    一.深入C#数据类型 值类型传递和引用类型传递 方法的参数是值类型和引用类型 注意:值传递和引用传递判定依据是有没有ref 01.如果方法的参数类型本身就是引用类型,那么对参数值的修改会永久保存 例如 ...

  8. LINQ Enumerable

    System.Linq.Enumerable类,提供了数十种称为扩展方法的共享方法,帮助您操作所有实现IEnumerable(of T)接口的类中的数据.由于Enumerable类的扩展方法可以处理许 ...

  9. OD: Heap Overflow (XP SP2 - 2003) & DWORD SHOOT via Chunk Resize

    微软在堆中也增加了一些安全校验操作,使得原本是不容易的堆溢出变得困难重重: * PEB Random:在 Windows XP SP2 之后,微软不再使用固定的 PEB 基址 0x7FFDF000,而 ...

  10. hdu 2544

    #include <iostream> #include <cstdio> #define INF 9999999 //#define INF 0x3f3f3f3 using ...