其他分享
首页 > 其他分享> > hwzer分块九讲

hwzer分块九讲

作者:互联网

1.区间加法,单点查询

#include<bits/stdc++.h>
using namespace std;
int n,opt,m,a[50005],vc,x,y,tg[50005],blo,tag[50005];
int read()
{
    long long 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*10+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
    cin>>n;
    blo=sqrt(n);m=n;
    for(int i=1;i<=n;i++)cin>>a[i],tag[i]=(i-1)/blo+1;
    while(m--)
    {
        opt=read();x=read();y=read();vc=read();
        if(!opt)
        {
            for(int i=x;i<=min(blo*tag[x],y);i++)a[i]+=vc;
            if(tag[x]!=tag[y])
            for(int i=blo*(tag[y]-1)+1;i<=y;i++)a[i]+=vc;
            for(int i=tag[x]+1;i<=tag[y]-1;i++)tg[i]+=vc;            
        }
        else cout<<a[y]+tg[tag[y]]<<endl;
    }
}

 

标签:opt,ch,50005,分块,read,九讲,int,blo,hwzer
来源: https://www.cnblogs.com/SFWR-YOU/p/11519683.html