在洛谷上点了个Splay的tag想玩玩,结果看到这题……

#include<bits/stdc++.h>
#define N 1000005
using namespace std;
typedef long long ll;
int n,m,top,a[N],q[N];
ll sum[N];
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
int main(){
    n=read();m=read();
    for(int i=1;i<=n;i++)a[i]=read();
    while(m--){
        int k=read(),ans=0;
        for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i]-k;
        top=0;
        for(int i=1;i<=n;i++)if(sum[q[top]]>sum[i])q[++top]=i;
        for(int i=n;i;i--){
            while(top&&sum[i]>=sum[q[top-1]])top--;
            ans=max(ans,i-q[top]);
        }
        printf("%d",ans);
        if(m)putchar(' ');else puts("");
    }
    return 0;
}

 

相关文章:

  • 2021-07-26
  • 2022-12-23
  • 2021-09-09
  • 2021-08-05
  • 2021-12-08
  • 2021-08-26
  • 2021-10-09
  • 2021-09-18
猜你喜欢
  • 2021-09-07
  • 2022-03-03
  • 2021-09-08
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
相关资源
相似解决方案