# 二维线段树学习笔记(区间操作)

$\sum_{i=1}^x a[i]$
$=\sum_{i=1}^x (x-i+1)*d[i]$

$S[i][j]=\sum_{i=1}^x \sum_{j=1}^y a[i][j]$

$a[i][j]=S[i][j]-S[i-1][j]-S[i][j-1]+S[i-1][j-1]$

$a[i][j]=\sum_{i=1}^x \sum_{j=1}^y d[i][j]$

$d[i][j]=a[i][j]-a[i-1][j]-a[i][j-1]+a[i-1][j-1]$

d[i][k]+=t,d[j+1][k]-=t,d[i][l+1]-=t,d[j+1][l+1]+=t;

$\sum_{i=1}^x\sum_{j=1}^y a[i][j]$

$=\sum_{i=1}^x\sum_{j=1}^y d[i][j]*(x-i+1)*(y-j+1)$

$=\sum_{i=1}^x\sum_{j=1}^y d[i][j]*(xy+x+y+1 - (x+1)j - (y+1)*i + i*j)$

$d[i][j],d[i][j]*i,d[i][j]*j,d[i][j]*i*j$

code:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
#define ll long long
#define mst(arr,x) memset(arr,x,sizeof(arr))
#define lowbit(x)   (x&(-x))
const int INF = 0x7fffffff;
const int N   = 2109;
int Read() {int ret=0,nag=1;char c=getchar();  while (c>'9'||c<'0') {if(c=='-') nag=-1;  c=getchar();}  while (c<='9'&&c>='0')    ret=(ret<<3)+(ret<<1)+c-'0',c=getchar();  return ret*nag;}
void Print(int x) {if(x<0) putchar('-'),x=-x;  if(x>9) Print(x/10);  putchar(x%10+'0');}
int n,m,d0[N][N],di[N][N],dj[N][N],dij[N][N];
char opt[3];
{
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=m;j+=lowbit(j))
d0[i][j]+=t,di[i][j]+=t*x,dj[i][j]+=t*y,dij[i][j]+=t*x*y;
}
{
int ret=0;
for(int i=x;i;i-=lowbit(i))
for(int j=y;j;j-=lowbit(j))
ret+=d0[i][j]*(x*y+x+y+1)-di[i][j]*(y+1)-dj[i][j]*(x+1)+dij[i][j];
return ret;
}
int main ()
{
#ifndef ONLINE_JUDGE
freopen("INPUT.in","r",stdin);
freopen("OUTPUT.out","w",stdout);
#endif
scanf("%*c%d%d",&n,&m);
while(scanf("%s",opt)!=EOF)
{
if(opt[0]=='L')
{
}