wangbw @ 2018-08-28 19:31:39
今天听老师讲这个区间最值。我回家用老师讲的方法做(是什么方法看代码),样例对了,兴奋地交上去,结果
#include<cstdio>
const int maxn=2000001;
int s[maxn],n,m;
int min(int x,int y)
{
if(x<y)
return x;
return y;
}
int search(int l,int r)
{
int mid=(l+r)/2;
if(l>r)
return 0;
if(l==r)
return s[l];
if(r-l==1)
return min(s[l],s[r]);
return min(search(l,mid),search(mid+1,r));
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&s[i]);
printf("0\n");
for(int i=2;i<=n;i++)
{
int a=i-m,b=i-1;
if(a<=0)
a=1;
printf("%d",search(a,b));
if(i!=n)
printf("\n");
}
return 0;
}
by clockwhite @ 2018-08-28 19:34:34
线段树了解一下qwq
by AThousandSuns @ 2018-08-28 19:38:56
单调队列了解一下qwq
by wangbw @ 2018-08-28 19:39:30
@邓兆昕 不太会
by wangbw @ 2018-08-28 19:40:06
@AThousandSuns 好的我没有用过
by WAMonster @ 2018-08-28 19:48:53
@wangbw 区间最值?树状数组吔可以!!
by Lolierl @ 2018-08-28 19:58:14
@wangbw
单队模板...不会就别做了吧[逃
by 斗神·君莫笑 @ 2018-08-28 20:04:26
@wangbw 单调队列谢谢
by wangbw @ 2018-08-28 23:02:53
刚刚愉快地
我干嘛要重复算那