题目描述
输入格式
输出格式
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int x[50005],sy[50005],fk[50005],n,opt,l,r,c,a,b,d,dx,cnt,bnt;
int main()
{
// freopen("a1.in","r",stdin);
// freopen("1.out","w",stdout);
cin>>n;
dx=sqrt(n);
bnt=1;
for(a=1;a<=n;a++)
{
scanf("%d",&x[a]);
sy[a]=(a-1)/dx+1;
}
for(a=1;a<=n;a++)
{
scanf("%d%d%d%d",&opt,&l,&r,&c);
if(opt==1)
{
printf("%d\n",x[r]+fk[sy[r]]);
}
else
{
if(sy[l]==sy[r])
{
for(b=l;b<=r;b++)
{
x[b]+=c;
}
continue;
}
int lf,ri;
lf=sy[l];
ri=sy[r];
for(b=l;b<=lf*dx;b++)
{
x[b]+=c;
}
for(b=(ri-1)*dx+1;b<=r;b++)
{
x[b]+=c;
}
for(b=lf+1;b<=ri-1;b++)
{
fk[b]+=c;
}
}
}
}