离人怎挽 @ 2019-01-10 11:32:43
萌新求助,九个MLE一个AC
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000001;
int n,m,a[maxn],ans;
struct node {
int minn;
} t[maxn<<2];
int lc(int p) {
return p<<1;
}
int rc(int p) {
return p<<1|1;
}
void push_up(int p) {
t[p].minn=min(t[lc(p)].minn,t[rc(p)].minn);
}
void build(int p,int l,int r) {
if(l==r) {
t[p].minn=a[l];
return ;
}
int mid=(l+r)>>1;
build(lc(p),l,mid);
build(rc(p),mid+1,r);
push_up(p);
}
int query(int x,int y,int l,int r,int p) {
if(x==l&&y==r) {
return t[p].minn;
}
int mid=(l+r)>>1;
if(y<=mid) return query(x,y,l,mid,lc(p));
else if(x>mid) return query(x,y,mid+1,r,rc(p));
else return min(query(x,y,l,mid,lc(p)),query(x,y,mid+1,r,rc(p)));
}
int main() {
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
scanf("%d",&a[i]);
build(1,1,n);
for(int i=1; i<=n; i++) {
if(i==1) cout<<'0'<<endl;
else {
printf("%d\n",query(i-m>0?i-m:1,i-1,1,n,1));
}
}
return 0;
}
by smarthehe @ 2019-01-10 12:44:11
by LJquq @ 2019-01-10 13:26:44
AC AC