题意:

矩阵上的单点更新,范围求和

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 1100
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int bit[N][N],n,m,a[N][N];
int lowbit(int x){
return x&(-x);
}
void add(int x,int y,int d){
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=n;j+=lowbit(j))
bit[i][j]+=d;
}
int sum(int x,int y){
int num=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
num+=bit[i][j];
return num;
}
int main()
{
int op,x1,x2,y1,y2,d;
while(~scanf("%d",&op)){
if(op==)break;
else if(op==){
scanf("%d",&n);
memset(bit,,sizeof(bit));
memset(a,,sizeof(a));
}
else if(op==){
scanf("%d%d%d",&x1,&y1,&d);
x1++;
y1++;
if(a[x1][y1]+d<)
d=-a[x1][y1];
add(x1,y1,d);
a[x1][y1]+=d;
}
else{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int tmp=sum(x2+,y2+)-sum(x2+,y1)-sum(x1,y2+)+sum(x1,y1);
printf("%d\n",tmp);
}
}
return ;
}

POJ 1195- Mobile phones(二维BIT)的更多相关文章

  1. poj 1195 Mobile phones(二维树状数组)

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

  2. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  3. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  4. ●POJ 1195 Mobile phones

    题链: http://poj.org/problem?id=1195 题解: 二维树状数组 #include<cstdio> #include<cstring> #includ ...

  5. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  6. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  7. POJ 1195 Mobile phones (二维树状数组)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  8. 题解报告:poj 1195 Mobile phones(二维BIT裸题)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  9. POJ 1195:Mobile phones 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16893   Accepted: 7789 De ...

  10. POJ 1195 Mobile phones【二维树状数组】

    <题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...

随机推荐

  1. 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)

    题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...

  2. linux入门教程(三) Linux操作系统的安装

    因为笔者一直都是使用CentOS,所以这次安装系统也是基于CentOS的安装.把光盘插入光驱,设置bios光驱启动.进入光盘的欢迎界面. 其中有两个选项,可以直接按回车,也可以在当前界面下输入 lin ...

  3. 2014-9-17二班----10 web project

    package cn.rwkj.servlet; import java.io.IOException; import javax.servlet.ServletException; import j ...

  4. JVM最多可创建多少线程

    JVM可支持的最大线程数 JVM最大线程数 (2012-07-04 23:20:15) 转载▼ 标签: jvm 最大线程数 it 分类: java分布式总结 摘自:http://sesame.itey ...

  5. MyEclipse 从数据库反向生成Hibernate实体类

    第一个大步骤 window-->open Perspective-->MyEclipse Java Persistence 进行了上面的 操作后会出现一个视图DB Brower:MyEcl ...

  6. 【Spring】Redis的两个典型应用场景--good

    原创 BOOT Redis简介 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结构,例如hashes, lists, sets等,同时支持数据持久化. ...

  7. JS代码片段:appendHTML 和 insertAdjacentHTML

    function appendHTML(container,html,position){ position =position || 'after'; var objE = document.cre ...

  8. 车牌识别LPR(七)-- 字符特征

    第七篇:字符特征 选择的字符特征应该满足以下条件: (1)选取的字符特征具有较强的鲁棒性,不受字符变形.弯曲等影响. (2)两个字符的字符特征不能完全相同,但部分相同是允许的,即选择的字符特征是唯一的 ...

  9. getpeername

    定义: int getpeername(int s, struct sockaddr *name, socklen_t *namelen); 描述: 获取socket的对方地址   得到对方的地址 s ...

  10. jumplist和changlist

    用jumplist可以在不同的访问过的位置之间跳转 C-O到上一个 C-I到下一个位置 :jumps列出跳转列表 changlist列出最近的改动点 g;到上一个,g,到下一个 :changes列出相 ...