70分,#2,#9,#10WA了
总体思路树状数组+差分
#2提示
Wrong Answer.wrong answer On line 1321 column 1, read 3, expected 1.
#include<cstdio>
#define int long long
class Tree
{
private:
static const int N=500005;
int c[N];
inline int lowbit(int x){return x&(-x);}
public:
void change(int x,int value,const int &n)
{
for(int i=x;i<=n;i+=lowbit(i)) c[i]+=value;
return;
}
int getsum(int x)
{
int sum=0;
for(int i=x;i;i-=lowbit(i)) sum+=c[i];
return sum;
}
int sum(int l,int r){return getsum(r)-getsum(l-1);}
void diff_change(int l,int r,int value,const int &n)
{
change(l,value,n);
change(r+1,-value,n);
return;
}
};
#undef int
int main()
{
#define int long long
Tree tr;
int n,m,cur,op,last=0;
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%lld",&cur);
tr.change(i,cur-last,n);
last=cur;
}
while(m--)
{
scanf("%lld",&op);
if(op==1)
{
int x,y,k;
scanf("%lld%lld%lld",&x,&y,&k);
tr.diff_change(x,y,k,n);
}
else
{
int x;
scanf("%lld",&x);
printf("%lld\n",tr.getsum(x));
}
}
return 0;
}