差一个测试点求调

P1440 求m区间内的最小值

jjhjiangjunhao @ 2024-08-03 09:01:43

#include<bits/stdc++.h>
using namespace std;
long long n,m,arr[100000000]={0};
deque<long long> d;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)scanf("%lld",&arr[i]);
    for(int i=1;i<=n;i++){
        if(i==1){
            cout<<0<<endl;
            continue ;
        }
        if(i-1>=m and arr[i-1-m]==d.front())d.pop_front();
        while(d.size() and arr[i-1]<d.back())d.pop_back();
        d.push_back(arr[i-1]); 
        printf("%lld\n",d.front());     
    }
    return 0;
}

第七个测试点RE\ 我单独下载下来单独测试也没有问题


by wenjunyi @ 2024-08-06 11:54:38

应把

if(i-1>=m and arr[i-1-m]==d.front())d.pop_front();

改成

if(d.size() && i-1>=m and arr[i-1-m]==d.front())d.pop_front();

by wenjunyi @ 2024-08-06 11:55:03

@jjhjiangjunhao


by wenjunyi @ 2024-08-06 11:55:51

求关注


by jjhjiangjunhao @ 2024-08-07 10:39:10

@wenjunyi OK,没问题


by wenjunyi @ 2024-08-07 10:41:25

OK


|