0分(7个点WA,3个点TLE)求查错

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

mcyqwq @ 2018-12-03 13:36:55

RT

暴力法

#include<iostream>
#include<cstdio>
using namespace std;
int a[1000001],minn[1000001],maxn[1000001],n,k;
inline int read()
{
    int x=0,uf=1; char c;
    c=getchar();
    if(c=='-') uf=-1,c=getchar();
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*uf;
}
inline int getmin(int a,int b)
{
    return a<b?a:b;
}
inline int getmax(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    n=read(); k=read();
    for(register int i=1;i<=n;i++) a[i]=read();
    for(register int i=k;i<=n;i++)
    {
        minn[i]=0x7ffffff; maxn[i]=-0x7ffffff;
        for(register int j=i;j>=i-k+1;j--)
        {
            minn[i]=getmin(minn[i],a[j]);
            maxn[i]=getmax(maxn[i],a[j]);
        }
    }
    for(register int i=k;i<=n;i++) printf("%d ",minn[i]);
    putchar('\n');
    for(register int i=k;i<=n;i++) printf("%d ",maxn[i]);
    return 0;
}

by nexox @ 2018-12-03 13:49:21

duang


by 用户已注销 @ 2018-12-03 14:43:12

这。。。暴力不 TLE 才怪


|