#2#10爆空间求助

P1440 求m区间内的最小值

mzyczzx @ 2022-03-21 12:49:25

#include<bits/stdc++.h>
using namespace std;
int a[3000010];
int mmin[3000010][27];
int n,m,l,r;
int v;
void rmq(){
    for(int j=1;j<=20;++j){
        for(int i=1;i<=n;++i){
            if(i+(1<<j)-1<=n){
                mmin[i][j]=min(mmin[i][j-1],mmin[i+(1<<(j-1))][j-1]);
            }
        }
    }
}
int mmmin(int ll,int rr){
    int x=log(rr-ll+1)/log(2);
    return (min(mmin[ll][x],mmin[rr+1-(1<<x)][x]));
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        cin>>v;
        a[i]=v;
        mmin[i][0]=v;
    }
    rmq();
    for(int i=1;i<=n;++i){
        if(i==1 && i<=m ){cout<<"0"<<endl;}
        else if(i<=m)cout<<mmmin(1,i-1)<<endl;
        else cout<<mmmin(i-m,i-1)<<endl;
    }
    return 0;
} 

by sw2022 @ 2022-03-21 13:12:34

125MB限制,你第二个数组肯定爆了啊


by Jerrlee✅ @ 2022-03-21 13:18:35

卡不过去的。。换做法吧


by eigw22h619 @ 2022-06-08 21:44:41

怎么就卡不过去了?滚动数组一下就可以了


|