POJ 1195 Mobile Phones
2014-01-27 11:13
393 查看
树状数组,开始的时候wa了,后来看看,原来是概率论没学好,以为求(L,B) - (R,T) 矩阵内的和只要用sum(R+1,T+1) - sum(L,B) 就行了,。傻x了。。
必须 sum(R,T) - sum(L,T) - sum(R,B) + sum(L,B) ; (R,T 已经自加1) 诫之。
代码:
View Code
必须 sum(R,T) - sum(L,T) - sum(R,B) + sum(L,B) ; (R,T 已经自加1) 诫之。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 1027 int c ; int n; int lowbit(int x) { return x&(-x); } void modify(int x,int y,int val) { for(int i=x;i<=n;i+=lowbit(i)) { for(int j=y;j<=n;j+=lowbit(j)) { c[i][j] += val; } } } int sum(int x,int y) { int res = 0; for(int i=x;i>0;i-=lowbit(i)) { for(int j=y;j>0;j-=lowbit(j)) { res += c[i][j]; } } return res; } int main() { int op,L,B,R,T,A,X,Y; while(scanf("%d",&op)!=EOF) { if(op == 3) break; else if(op == 0) { memset(c,0,sizeof(c)); scanf("%d",&n); } else if(op == 1) { scanf("%d%d%d",&X,&Y,&A); X++;Y++; modify(X,Y,A); } else if(op == 2) { scanf("%d%d%d%d",&L,&B,&R,&T); R++;T++; printf("%d\n",sum(R,T)-sum(L,T)-sum(R,B)+sum(L,B)); } } return 0; }
View Code
相关文章推荐
- poj 1195 mobile phones 二维树状数组
- POJ 1195 Mobile phones
- 二维树状数组 —— POJ 1195 Mobile phones
- 【POJ 1195】Mobile phones
- POJ 1195 Mobile phones 二维树状数组
- POJ1195 Mobile phones
- poj1195 Mobile phones
- POJ 1195 Mobile phones
- POJ-1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones
- POJ_1195 Mobile phones 【二维树状数组】
- poj 1195 Mobile phones
- POJ 1195 Mobile phones
- POJ 1195:Mobile phones 二维树状数组
- poj1195 Mobile phones 二维线段树和二维树状数组两种做法 树套树
- POJ 1195 Mobile phones
- poj 1195 Mobile phones
- 【二维树状数组】poj 1195 Mobile phones
- poj1195 Mobile phones
- ●POJ 1195 Mobile phones