wa了4个点,大佬们救救我呀

P1440 求m区间内的最小值

chases92 @ 2019-03-18 12:18:10

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int>P;
const int INF=4e8;
const int N=2000015,mod=32767;

int a[N],ans[N],Q[N];
int n,m;

void min_num(){
    int head=1,tail=0;
    for(int i=1;i<n;i++){
        while(head<=tail&&Q[head]<=i-m)head++;
        while(head<=tail&&a[Q[head]]>=a[i])tail--;
        Q[++tail]=i;
        printf("%d\n",a[Q[head]]);
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    printf("0\n");
    min_num();
}

by hfee @ 2019-03-18 12:27:01

气势磅礴的头文件


by chases92 @ 2019-03-18 12:44:07

while(head<=tail&&a[Q[head]]>=a[i])tail--;

改成

while(head<=tail&&a[Q[tail]]>=a[i])tail--;

就好了,呜呜呜我可能是个傻子


by chases92 @ 2019-03-18 12:44:20

@白狼与玫瑰 哈哈哈


by WANJ @ 2019-03-18 13:16:22

.


by 小罐猹 @ 2019-03-26 18:06:41

...


|