90求助,#9,TLE

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

lisiyuan19 @ 2022-07-18 14:15:39

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[10000010];int maxn[10000010],minn[10000010];
int main(){
    memset(maxn,-1000001,sizeof(maxn));
    memset(minn,1000001,sizeof(minn));
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
//      cout<<"a[i]="<<a[i]<<endl;
    }for(int i=0;i+k-1<n;i++){
        for(int j=i;j<i+k;j++){
            if(maxn[i]<a[j]){
                maxn[i]=a[j];
//              cout<<"a[i]="<<a[i]<<" ";
//              cout<<"maxn="<<maxn[i]<<endl;
            } 

            if(minn[i]>a[j]){
                minn[i]=a[j];
//              cout<<"minn="<<minn[i]<<endl;
            } 
        }
    }
    for(int i=0;i+k-1<n;i++){
        printf("%d ",minn[i]);
    }printf("\n");
    for(int i=0;i+k-1<n;i++){
        printf("%d ",maxn[i]);
    }

    return 0; 
} 

by Hisaishi_Kanade @ 2022-07-18 14:16:25

不是正解


by lisiyuan19 @ 2022-07-18 14:43:52

什么意思


by lisiyuan19 @ 2022-07-18 14:44:34

能拿<queue>做吗


|