为什么会有两个MLE

P1440 求m区间内的最小值

William_Takazaki @ 2023-05-13 19:36:34

啊啊啊啊啊

#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10,L=20;
int n,m,a[N],f[N][L],lg[N];
int main(){
    int i,j;
    cin>>n>>m;
    for(i=1;i<=n;i++)cin>>a[i];
    lg[1]=0;
    for(i=2;i<=n;i++)lg[i]=lg[i/2]+1;
    for(j=0;j<L;j++){
        for(i=1;i+(1<<j)-1<=n;i++){
            if(j==0)f[i][j]=a[i];
            else f[i][j]=min(f[i][j-1],f[i+(1<<j-1)][j-1]);
        }
    }for(i=1;i<=n;i++){
        int x,y,k;
        if(i==1)cout<<"0\n";
        else{
            if(i<=m){
                x=1;
                y=i-1;
            }else{
                x=i-m;
                y=i-1;
            }k=lg[y-x+1];
            cout<<min(f[x][k],f[y-(1<<k)+1][k])<<endl;  
        }
    }
    return 0;
}

by Leonid @ 2023-05-13 19:53:33

@xixi 显然是可以的


by wind_kaka @ 2023-05-13 19:54:42

我上次嫌线段树麻烦,没有糊(((


by wind_kaka @ 2023-05-13 19:55:05

哼!啊啊啊啊啊!(幻视


by William_Takazaki @ 2023-05-13 19:56:22

@h0494 @xixi 气死了啊啊啊啊啊,这个就不卡你ST表


by wind_kaka @ 2023-05-13 19:59:23

@6371 6 还是 7 倍经验好像只有这道咔了


by William_Takazaki @ 2023-05-13 20:32:46

@Light_az ?


by Light_az @ 2023-05-13 20:34:49

@6371 看错了


上一页 |