poj 1195 Mobile phones(树状数组二维)
来源:互联网 发布:疯狂的美图美工助手 编辑:程序博客网 时间:2024/05/21 22:29
这是道模版题,直接套模版就好了。。。。
注意:我用的树状数组下标是从1开始的,而题目给定是从0开始的,所以有时要+1
#include<stdio.h>
#define N 1100
int n;
int bit[N][N];
void add(int x,int y,int v)
{
int i,j;
for(i=x;i<=n;i+=i&-i)
for(j=y;j<=n;j+=j&-j)
bit[i][j]+=v;
}
int sum(int x,int y)
{
int res=0,i,j;
for(i=x;i>0;i-=i&-i)
for(j=y;j>0;j-=j&-j)
res+=bit[i][j];
return res;
}
int main(void)
{
int judge,c,x1,y1,x2,y2,i,j;
scanf("%d%d",&judge,&n);
while(~scanf("%d",&judge)&&judge!=3)
{
if(judge==1)
{
scanf("%d%d%d",&x1,&y1,&c);
add(x1+1,y1+1,c);
}
else
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("%d\n",sum(x2+1,y2+1)-sum(x2+1,y1)-sum(x1,y2+1)+sum(x1,y1));
}
}
}
- 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 (二维树状数组)
- 解锁bios学习总结
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
- spring cloud eureka 集群 服务集群 测试
- 不考虑重复字符的字符串组合
- Android Manifest merger failed with multiple errors解决思路
- poj 1195 Mobile phones(树状数组二维)
- 计算机网络体系结构
- layer---弹出多个iframe如何找到父页面方法
- 一些经典的iOS博客
- Win7下打开所有程序打开方式都是Windows Media Center解决办法
- MVC,MVP 和 MVVM 的图示
- [LNMPA搭建六]Apache服务器详细【配置】
- Google你能把Android的多媒体搞得再烂一些吗
- 复杂的世界 一个就够了