POJ 1195 Mobile phones(二维树状数组)
来源:互联网 发布:软件许可 编辑:程序博客网 时间:2024/06/05 04:31
题目链接:
POJ 1195 Mobile phones
题意:
一个
要求对每次查询输出结果。
分析:
题目中的原始下标是从0开始的,可以人为地每次都+1,这样就是从1开始的了。
用sum[i][j]来代替原来一维树状数组中的sum[i],那么每次查询相当于
∑sum[L,R] +∑sum[L−1,R−1] -∑sum[L−1,T] -∑sum[R,B−1] ,
其中sum[L,R]表示1<=i<=L,1<=j<=R的所有树状数组查找的有效sum[i][j] 和,其余类似。
//5076K 1032MS#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int maxn=1100;int com,n,x,y,num,left,below,right,top,ans;int sum[maxn][maxn];inline void update(){ for(int i=x;i<=n;i+=(i&(-i))){ for(int j=y;j<=n;j+=(j&(-j))){ sum[i][j]+=num; } }}inline int solve(int MAX_X,int MAX_Y){ int res=0; for(int i=MAX_X;i>0;i-=(i&(-i))){ for(int j=MAX_Y;j>0;j-=(j&(-j))){ res+=sum[i][j]; } } return res;}int main(){ freopen("poj1195in.txt","r",stdin); freopen("myout.txt","w",stdout); while(~scanf("%d",&com)&&com!=3){ if(com==0){ scanf("%d",&n); memset(sum,0,sizeof(sum)); }else if(com==1){ scanf("%d%d%d",&x,&y,&num); x++;y++; update(); }else { scanf("%d%d%d%d",&left,&below,&right,&top); left++;below++;right++;top++; ans=solve(right,top)+solve(left-1,below-1)-solve(right,below-1)-solve(left-1,top); printf("%d\n",ans); } } return 0;}
0 0
- 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 二维树状数组
- Mobile Phones poj 1195--二维树状数组
- 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 二维树状数组
- poj 1195 Mobile phones(二维树状数组)
- poj 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones (二维树状数组)
- 龙书D3D11章节习题答案(第四章)
- PAT (Advanced Level) Practise 1103 Integer Factorization (30)
- spring学习笔记(24)基于注解配置事务
- 弦月下的SQL<7> 游标和事务
- codevs 1041 Car 的旅行路线 最短路+代码能力
- POJ 1195 Mobile phones(二维树状数组)
- Hibernate主键生成策略的类型的使用说明
- 第4周项目1 求最大公约数
- js中this指向总结
- 弦月下的SQL<8> SQL存储过程和触发器代码
- JDBC连接SqlServer
- 那么蒙特卡洛树搜索(Monte Calro Tree Search, MCTS)究竟是啥
- js删除数组里的某个元素
- 必须知道的十二大著名法则