萌新妹子求教

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

Zkxxxv_h @ 2019-06-25 10:58:31

#2 #7 WA

#include<iostream>
#include<cstdio>
using namespace std;
#define A 1000001
int n,k;
int zuida[A],zuixiao[A];//存最大最小
struct node{
    int left,right,minx,maxx;
}tree[A*4+10];
void build(int index,int l,int r)
{
    tree[index].left=l,tree[index].right=r;
    if(l==r)
    {
        int x;
        scanf("%d",&x);
        tree[index].maxx=tree[index].minx=x;
        return ;
    }
    int mid=(l+r)>>1;
    build(index<<1,l,mid),build(index<<1|1,mid+1,r);
    tree[index].minx=min(tree[index<<1].minx,tree[index<<1|1].minx);
    tree[index].maxx=max(tree[index<<1].maxx,tree[index<<1|1].maxx);
    return ;
}
int intervalaskd(int index,int l,int r)//查最大
{
    if(tree[index].left>=l&&tree[index].right<=r)
        return tree[index].maxx;
    int temp=-0x7ffffff;
    if(tree[index<<1].right>=l)
        temp=max(temp,intervalaskd(index<<1,l,r));
    if(tree[index<<1|1].left<=r)
        temp=max(temp,intervalaskd(index<<1|1,l,r));
    return temp;
}
int intervalaskx(int index,int l,int r)//查最小
{
    if(tree[index].left>=l&&tree[index].right<=r)
        return tree[index].minx;
    int temp=0x7ffffff;
    if(tree[index<<1].right>=l)
        temp=min(temp,intervalaskx(index<<1,l,r));
    if(tree[index<<1|1].left<=r)
        temp=min(temp,intervalaskx(index<<1|1,l,r));
    return temp;
}
int main(){
    scanf("%d%d",&n,&k);
    build(1,1,n);
    for(int i=1;i<=n-k+1;i++)
    {
        zuida[i]=intervalaskd(1,i,i+k-1);
        zuixiao[i]=intervalaskx(1,i,i+k-1);
    }
    for(int i=1;i<=n-k+1;i++)
        printf("%d ",zuixiao[i]);
    cout<<endl;
    for(int i=1;i<=n-k+1;i++)
        printf("%d ",zuida[i]);
}

by Aliemo @ 2019-06-25 10:59:49

你是妹子么??????????


by Zkxxxv_h @ 2019-06-25 11:01:29

@情谊。。碎情 重点在代码a ..


by Zkxxxv_h @ 2019-06-25 11:03:20

已查错,此贴已结


by GavinZheng @ 2019-07-19 08:00:45

@胖虎x 您好,为什么您要强调您是妹子呢


|