题意:

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

#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. crontab 指定执行用户

    linux下可以通过配置crontab来定时执行任务,执行体可以是一条系统命令或自己写的一个脚本,同时可以指派用户来执行.配置crontab有两种方法.方法1.使用crontab命令,例如添加一个新的 ...

  2. cojs 简单的区间问题 解题报告

    新学了些弦图和区间图的新玩意,于是就想着出一道题目 其实这道题不用弦图和区间图的理论也是可以做的 首先考虑第一问,第一问是一个NOIP普及组水平的贪心 我们把区间按照右端点从小到大排序,之后从头到尾扫 ...

  3. 机器人学 —— 轨迹规划(Introduction)

    轨迹规划属于机器人学中的上层问题,其主要目标是计划机器人从A移动到B并避开所有障碍的路线. 1.轨迹计划的对象 轨迹规划的对象是map,机器人通过SLAM获得地map后,则可在地图中选定任意两点进行轨 ...

  4. javascript正则表达式控制input只能输入数字

    不能输入中文 <input type="text" name="textfield"  onkeyup="this.value=this.val ...

  5. java web 下实现文件下载

    来自:http://blog.csdn.net/longshengguoji/article/details/39433307 需求:实现一个具有文件下载功能的网页,主要下载压缩包和图片 两种实现方法 ...

  6. 车牌识别LPR系统系列文章汇总

    这里的LPR的的几篇文章是之前项目的一些相关资料的整理,涉及实验室内部的资料就没有放上来,希望能对想了解这方面的同学,有所帮助,那怕了解个大概也好.知道整体的思路就好.当初就是一个人瞎摸索,走了很多的 ...

  7. PHP Redis 普通封装类

    class redisInit { private $redis; //redis对象 /** * 初始化Redis * $config = array( * 'server' => '127. ...

  8. .net 程序员成长路线图?

    https://www.zhihu.com/question/25474641 得看赵四本, @赵劼 推荐的. CLR via C# .net Essentials C# in Depth Frame ...

  9. Android 按键消息处理Android 按键消息处理

    在android系统中,键盘按键事件是由SystemServer服务来管理的:然后在以消息的形式分发给应用程序处理.产生键盘按键事件则是有Linux kernel的相关驱动来实现. 键盘消息有别于其他 ...

  10. MyBatis 实践 -动态SQL/关联查询

    MyBatis 实践 标签: Java与存储 动态SQL 动态SQL提供了对SQL语句的灵活操作,通过表达式进行判断,对SQL进行拼接/组装. if 对查询条件进行判断,如果输入参数不为空才进行查询条 ...