题目:上帝造题的七分钟
思路:
嗯听说是二维树状数组的区间修改+区间查询。
然后在洛谷不开O2 TLE ,开了O2 RE,且分数在55~100不等…
在joyoi过了的…
代码:
(交上去不一定能过)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;#define lowbit(x) (x&-x)#define ll long long
#define db doublevoid readc(char& x) {while(!isalpha(x)) x=getchar();
}void read(int& x) {scanf("%d",&x);
}void writell(ll x) {printf("%lld",x);
}void write(int x) {printf("%d",x);
}void writen() {printf("\n");
}void writew() {printf(" ");
}#define maxn 2048int n,m;
int a[maxn+2][maxn+2];
int ai[maxn+2][maxn+2];
int aj[maxn+2][maxn+2];
int aij[maxn+2][maxn+2];void adda(int x,int y,int k) {while(x<=n) {int yy=y;while(y<=m) {a[x][y]+=k;y+=lowbit(y);}x+=lowbit(x);y=yy;}
}void addai(int x,int y,int k) {while(x<=n) {int yy=y;while(y<=m) {ai[x][y]+=k;y+=lowbit(y);}x+=lowbit(x);y=yy;}
}void addaj(int x,int y,int k) {while(x<=n) {int yy=y;while(y<=m) {aj[x][y]+=k;y+=lowbit(y);}x+=lowbit(x);y=yy;}
}void addaij(int x,int y,int k) {while(x<=n) {int yy=y;while(y<=m) {aij[x][y]+=k;y+=lowbit(y);}x+=lowbit(x);y=yy;}
}int suma(int x,int y) {int s=0;while(x>0) {int yy=y;while(y>0) {s+=a[x][y];y-=lowbit(y);}x-=lowbit(x);y=yy;}return s;
}int sumai(int x,int y) {int s=0;while(x>0) {int yy=y;while(y>0) {s+=ai[x][y];y-=lowbit(y);}x-=lowbit(x);y=yy;}return s;
}int sumaj(int x,int y) {int s=0;while(x>0) {int yy=y;while(y>0) {s+=aj[x][y];y-=lowbit(y);}x-=lowbit(x);y=yy;}return s;
}int sumaij(int x,int y) {int s=0;while(x>0) {int yy=y;while(y>0) {s+=aij[x][y];y-=lowbit(y);}x-=lowbit(x);y=yy;}return s;
}void Add(int x,int y,int k){adda(x,y,k);addai(x,y,k*x);addaj(x,y,k*y);addaij(x,y,k*x*y);
}int Sum(int x,int y){return suma(x,y)*(x*y+x+y+1)-sumai(x,y)*(y+1)-sumaj(x,y)*(x+1)+sumaij(x,y);
}int main() {char opr;readc(opr);read(n);read(m);while(true) {while(~scanf("%c",&opr)&&!isalpha(opr));if(!isalpha(opr)) break;if(opr=='L') {int x,y,s,t,k;read(x);read(y);read(s);read(t);read(k);x++,y++,s++,t++;Add(s+1,t+1,k);Add(s+1,y,-k);Add(x,t+1,-k);Add(x,y,k);} else {int x,y,s,t;read(x);read(y);read(s);read(t);x++,y++,s++,t++;write(Sum(s,t)-Sum(s,y-1)-Sum(x-1,t)+Sum(x-1,y-1));writen();}} return 0;
}