RE求助!

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

眼镜犬 @ 2020-02-16 14:21:54

1和3AC,其它 全部 RE 了QAQ


#include<bits/stdc++.h>
using namespace std;
inline int read(){
    char c=getchar();int num=0;bool b=0;
    for(;c<'0'||c>'9';b=(c=='-'?1:0),c=getchar());
    for(;c>='0'&&c<='9';num=(num<<3)+(num<<1)+(c^'0'),c=getchar());
    return b?-num:num;
}
int que[101];
int front=1,rear=1;
void push(int a){
    if(rear<100){
        que[rear++]=a;
    }
}
bool isNull(){
    return front=rear;
}
void pop(){
    if(front!=rear){
        front++;
    }
}
int len(){
    return rear-front;
}
int n,k,j,max1,min1;
int a[100],max2[100],min2[100];
int main(){
    n=read();
    k=read();
    for(int i=1;i<=n;i++){
        a[i]=read();
    }
    for(int i=1;i<=k-1;i++){
        push(a[i]);
    } 
    for(int i=k;i<=n;i++){
        push(a[i]);
        max1=-100000000;
        min1=100000000;
        for(int j=i-k+1;j<=i;j++){
            if(a[j]>max1){
                max1=a[j];
            }
            if(a[j]<min1){
                min1=a[j];
            }
        }
        max2[i]=max1;
        min2[i]=min1;
    }
    for(int i=k;i<=n;i++){
        cout<<min2[i]<<" ";
    }
    cout<<endl;
    for(int i=k;i<=n;i++){
        cout<<max2[i]<<" ";
    }
    return 0;
}

by Wenoide @ 2020-02-16 14:24:40

@眼镜犬 不是 10^6 吗?


by 眼镜犬 @ 2020-02-16 14:35:50

@ScanfN 改小也没用捏


by Stephen_Curry @ 2020-02-16 14:43:25

@眼镜犬

1\le k\le n \le 10^6

所以您把几个数组都只开到 100 不 RE 才怪……


|