30 分wa一个点
查看原帖
30 分wa一个点
819719
lidxy楼主2023/10/3 15:43
#include<bits/stdc++.h>
using namespace std;
using ll=long long; 
constexpr int N=200005;
int n,q;
ll a[N];
ll sum[N];
ll w[N];
ll sum1[N];
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f;}
signed main()
{
    cin.tie(0);
    cout.tie(0);
    n=read(),q=read();
    for(int i=1;i<=n;++i)
    {
        a[i]=read();
        w[i]=w[i-1]+a[i];
    }
    int l=1;
    int biao=0;
    for(int i=1;i<=n;++i)
    {
        sum[i]=sum[i-1];
        if(a[i]>0)
        {
            biao=0;
            for(int j=l;j<=i;++j)
            {
                if(w[i]-w[j-1]>0)
                {
                    sum[i]++;
                    if(j!=i)
                    {
                            sum1[j]=sum1[j-1]+1;
                    }
                }
            }
            l=i+1;
        }
        else
        {
            if(!biao)
            {
                l=i;
                biao=1;
            }
        }
    }
    while(q--)
    {
        int ql=read(),qr=read();
        if(ql==qr)
        {
            if(a[ql]>0)cout<<1;
            else cout<<0;
        }
        else cout<<sum[qr]-sum[ql-1]-sum1[ql-1];
        putchar('\n');
    }
    // for(int i=1;i<=n;++i)
    // {
    //     cout<<sum1[i]<<" ";
    // }
}
2023/10/3 15:43
加载中...