幽默空间
查看原帖
幽默空间
544279
wh__楼主2024/10/24 16:37

有大佬能看看还能再卡卡吗 XD

提交记录

#include<bits/stdc++.h>
typedef long long LL;
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define fi first
#define se second
#define eb(x) emplace_back(x)
using namespace std;
const int SIZE=1e5+2;
int n,m;
int a[SIZE];
char lg[SIZE];
struct block
{
    LL pre[SIZE];
    int st[SIZE][20];
    LL R;
    void init(LL l,LL r)
    {
        R=r;
        for(int i=1;i<=n;i++)
        {
            pre[i]=pre[i-1];
            if(a[i]>=l && a[i]<=r)
            {
                st[i][0]=a[i];
                pre[i]+=a[i];
            }
            else st[i][0]=inf;
        }
        for(int j=1;j<=lg[n];j++)
            for(int i=1;i<=n;i++)
                st[i][j]=min(st[i][j-1],st[i+(1<<j-1)][j-1]);
    }
    LL queryM(int l,int r)
    {
        char len=lg[r-l+1];
        return min(st[l][len],st[r-(1<<len)+1][len]);
    }
    LL queryS(int l,int r)
    {
        return pre[r]-pre[l-1];
    }
}bl[30];
LL read()
{
    LL x=1,res=0;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')x=-1;ch=getchar();}
    while(isdigit(ch)){res=(res<<3)+(res<<1)+(ch^48);ch=getchar();}
    return x*res;
}
signed main()
{
    // freopen("xx.in","r",stdin);
    // freopen("xx.out","w",stdout);
    n=read();
    for(int i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
    for(int i=1;i<=n;i++) a[i]=read();
    bl[0].init(1,1);
    LL tmp=2;
    for(int i=1;i<30;i++)
    {
        bl[i].init(tmp,tmp+tmp-1);
        tmp<<=1;
    }
    m=read();
    while(m--)
    {
        int l=read(),r=read();
        LL x=0;
        for(int i=0;i<30;i++)
        {
            if(x+1<min(bl[i].queryM(l,r),bl[i].R)) break;
            x+=bl[i].queryS(l,r);
        }
        printf("%lld\n",x+1);
    }
    return 0;
}
2024/10/24 16:37
加载中...