1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream> #include <cstdlib> #include <algorithm> #define lowbit(x) (x) & -(x) #define maxn 2050 #define re register int BIT[4][maxn][maxn] , n , m , x , y , a , b , v; char c; inline int read() { int x = 0 , f = 1; char ch = getchar(); while(ch > '9' || ch < '0') { if(ch == '-') f= -1; ch = getchar(); } while(ch <= '9' && ch >= '0') x = (x<<3) + (x<<1) + ch - 48 , ch = getchar(); return x*f; } inline int query(int tr , int x , int y) { int ans = 0; for(re int i = x ; i ; i -= lowbit(i)) for(re int j = y ; j ; j -= lowbit(j)) ans += BIT[tr][i][j]; return ans; } inline int rangeSum(int x, int y) { return query(0,x,y)*(x+1)*(y+1) - query(1,x,y)*(y+1) - query(2,x,y)*(x+1) + query(3,x,y); } inline void (int x , int y , int v) { for(re int i = x ; i <= n ; i += lowbit(i)) for(re int j = y ; j <= m ; j += lowbit(j)) BIT[0][i][j] += v , BIT[1][i][j] += v*x , BIT[2][i][j] += v*y , BIT[3][i][j] += v*x*y; } int main() { std::cin>>c; scanf("%d%d",&n,&m); while(std::cin>>c) { if(c == 'L') { a = read() , b = read() , x = read() , y = read() , v = read(); update(a,b,v) , update(a,y+1,-v), update(x+1,b,-v) , update(x+1,y+1,v); } else if(c == 'k') { a = read() , b = read() , x = read() , y = read() ; printf("%dn",rangeSum(x,y)-rangeSum(x,b-1)-rangeSum(a-1,y)+rangeSum(a-1,b-1)); } } }
|
近期评论