Ybw0731 @ 2024-10-09 22:26:27
#include<bits/stdc++.h>
using namespace std;
const int N=8e6+100;
int n,m,a[N],sum[N],x,y;
void build(int o,int l,int r){
if(l==r){
sum[o]=a[l];
return;
}
int mid=(l+r)/2;
build(o*2,l,mid);
build(o*2+1,mid+1,r);
sum[o]=min(sum[o*2],sum[o*2+1]);
}
int query(int o,int l,int r){
if(x<=l&&r<=y)return sum[o];
int ans=INT_MAX,mid=(l+r)/2;
if(x<=mid)ans=min(query(o*2,l,mid),ans);
if(y>mid)ans=min(query(o*2+1,mid+1,r),ans);
return ans;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
cout<<0<<endl;
for(int i=2;i<=n;i++){
int x=max(i-m,1),y=i-1;
cout<<query(1,1,n)<<endl;
}
return 0;
}
by __yun__ @ 2024-10-09 22:45:02
将
for(int i=2;i<=n;i++){
int x=max(i-m,1),y=i-1;
cout<<query(1,1,n)<<endl;
}
改为
for(int i=2;i<=n;i++){
x=max(i-m,1),y=i-1;
cout<<query(1,1,n)<<endl;
}
by __yun__ @ 2024-10-09 22:45:41
个人建议:将
by __yun__ @ 2024-10-09 22:45:49
@Ybw0731
by Ybw0731 @ 2024-10-10 21:31:53
@yun,我是SB,现在AC了,已关注