MLE

P1886 滑动窗口 /【模板】单调队列

gwx123456 @ 2019-04-22 15:44:11

求大佬看一下为什么三个点MLE

#include <bits/stdc++.h>
using namespace std;
int m,n,z[1000001],fx[1000001][17],fn[1000001][17];
int ansmax[1000001],ansmin[1000001];
int Askmax(int L,int R){
    int k;
    k=int(log(R-L+1)/log(2));
    return max(fx[L][k],fx[R+1-(1<<k)][k]);
}
int Askmin(int L,int R){
    int k;
    k=int(log(R-L+1)/log(2));
    return min(fn[L][k],fn[R+1-(1<<k)][k]);
}
int main(){
    cin>>m>>n;
    for(int i=1;i<=m;i++)
        scanf("%d",&z[i]);
    for(int i=1;i<=m;i++)
        fx[i][0]=fn[i][0]=z[i]; 

    for(int j=1;j<=18;j++) 
        for(int i=1;i+(1<<j)-1<=m;i++)
            fx[i][j]=max(fx[i][j-1],fx[i+(1<<(j-1))][j-1]); 

    for(int j=1;j<=18;j++) 
        for(int i=1;i+(1<<j)-1<=m;i++)
            fn[i][j]=min(fn[i][j-1],fn[i+(1<<(j-1))][j-1]); 

    for(int i=1;i<=m-n+1;i++){
        int a,b;
        a=i;b=a+n-1;
        ansmin[i]=Askmin(a,b);
        ansmax[i]=Askmax(a,b);
    }
    for(int i=1;i<=m-n+1;i++)
        cout<<ansmin[i]<<" ";
    cout<<endl;
    for(int i=1;i<=m-n+1;i++)
        cout<<ansmax[i]<<" ";
    return 0;
}

by herolxl @ 2019-04-22 16:07:31

交个盆友鸭


by 单曦增 @ 2019-04-22 16:32:10

@gwx123456 你的数组开大了呗


by gwx123456 @ 2019-04-22 16:48:49

不开大会RE


|