标签:
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 18185 | Accepted: 8399 |
Description
Input
Output
Sample Input
0 4 1 1 2 3 2 0 0 2 2 1 1 1 2 1 1 2 -1 2 1 1 2 3 3
Sample Output
3 4
Source
1 #include <cstdio> 2 #include <cstring> 3 #define lowbit(x) (x)&(-x) 4 5 int S; 6 int c[1030][1030]; 7 8 void add(int x, int y, int val) 9 { 10 for(int i = x; i <= S; i += lowbit(i)) 11 for(int j = y; j <= S; j +=lowbit(j)) 12 c[i][j] += val; 13 } 14 15 int sum(int x, int y) 16 { 17 int ret = 0; 18 for(int i = x; i > 0; i -= lowbit(i)) 19 for(int j = y; j > 0; j -= lowbit(j)) 20 ret += c[i][j]; 21 return ret; 22 } 23 24 int getans(int x1, int y1, int x2, int y2) 25 { 26 return sum(x2, y2)-sum(x1-1, y2)-sum(x2, y1-1)+sum(x1-1, y1-1); 27 } 28 29 int main() 30 { 31 int op; 32 while(scanf("%d", &op), op != 3){ 33 if(op == 0){ 34 scanf("%d", &S); 35 memset(c, 0, sizeof(c)); 36 } 37 else if(op == 1){ 38 int x, y, a; 39 scanf("%d%d%d", &x, &y, &a); 40 add(x+1, y+1, a); //坐标全部加1 41 } 42 else if(op == 2){ 43 int l, b, r, t; 44 scanf("%d%d%d%d", &l, &b, &r, &t); 45 printf("%d\n", getans(l+1, b+1, r+1, t+1)); //坐标全部加1 46 } 47 } 48 return 0; 49 }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5722911.html