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 ;
}