题目链接:http://poj.org/problem?id=1195

【题意】

给出一个全0的矩阵,然后一些操作
0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次
1 X Y A:对于矩阵的X,Y坐标增加A
2 L B R T:询问(L,B)到(R,T)区间内值的总和
3:结束对这个矩阵的操作
 
【思路】
二维树状数组单点更新+区域查询,可作为模板题。
注意坐标是从0开始,所以要+1
 
【代码】
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
const int N = ;
typedef long long LL;
int c[N][N], n;
int lowbit(int x)
{
return x & (-x);
}
void update(int x, int y, int num)
{
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= n; j += lowbit(j))
c[i][j] += num;
}
int query(int x, int y)
{
int sum = ;
for(int i = x; i > ; i -= lowbit(i))
for(int j = y; j > ; j -= lowbit(j))
sum += c[i][j];
return sum;
}
int main()
{
int i, m;
scanf("%d%d", &i, &n);
while(scanf("%d", &m), m != )
{
int x1, x2, y1, y2, num;
if(m == )
{
scanf("%d%d%d", &x1, &y1, &num);
x1++, y1++;
update(x1, y1, num);
}
else
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1++, y1++, x2++, y2++;
printf("%d\n", query(x2, y2) - query(x1 - , y2) - query(x2, y1 - ) + query(x1 - , y1 - ));
}
}
return ;
}

【poj1195】Mobile phones(二维树状数组)的更多相关文章

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

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

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

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

  3. 【POJ1195】【二维树状数组】Mobile phones

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

  4. Mobile phones_二维树状数组

    [题意]给你一个矩阵(初始化为0)和一些操作,1 x y a表示在arr[x][y]加上a,2 l b r t 表示求左上角为(l,b),右下角为(r,t)的矩阵的和. [思路]帮助更好理解树状数组. ...

  5. poj1195Mobile phones(二维树状数组)

    http://poj.org/problem?id=1195 模版题 i写成k了 找了一个多小时没找出来.. #include <iostream> #include<cstring ...

  6. poj_1195Mobile phones,二维树状数组

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...

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

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

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

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

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

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

随机推荐

  1. Django继承

    Django目前支持两种不同的继承方式,包括抽象基础类和多表继承. 1.抽象基础类: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 cla ...

  2. 记一次centos7挂在nas盘的踩坑经过

    p:first-child, #write > ul:first-child, #write > ol:first-child, #write > pre:first-child, ...

  3. jQuery Mobile 手动显示ajax加载器

    在jquery mobile开发中,经常需要调用ajax方法,异步获取数据,如果异步获取数据方法由于网速等等的原因,会有一个反应时间,如果能在点击按钮后数据处理期间,给一个正在加载的提示,客户体验会更 ...

  4. python16_day02【列表、字典】

    1.列表 names = ['Alex',"Tenglan",'Eric'] >>> names[0] 'Alex' >>> names[2] ...

  5. Django-MTV(Day66)

    阅读目录 Django基本命令 视图层路由配置系统 视图层之视图函数 MTV模型 Django的MTV分别代表: Model(模型):负责业务对象与数据库的对象(ORM) Template(模板):负 ...

  6. day3-python的函数及参数

    函数式编程最重要的是增强代码的重用性和可读性 1 2 3 4 def 函数名(参数):     ...     函数体     ... 函数的定义主要有如下要点: def:表示函数的关键字 函数名:函 ...

  7. kubeadm方式安装kubernetes

    系统: Ubuntu 18.04.2 LTS 内存: 8G 机器: 属性 IP Hostname ssh  Master  192.168.91.48 blackray-pc     node1  1 ...

  8. Zabbix linux agent 安装

    系统:Linux Centos 7.3 x64 服务:Zabbix_agent 3.0.16 一.安装Zabbix_agent 服务 1.安装zabbix 3.0 yum源 rpm -ivh http ...

  9. windows 安装python3.5启动报错:api-ms-win-crt-runtime-l1-1-0.dll丢失

    下载: api-ms-win-crt-runtime就是MFC的运行时环境的库,python在windows上编译也是用微软的visual studio C++编译的,底层也会用到微软提供的C++库和 ...

  10. toLatin1 toLocal8Bit

    toLatin1.toLocal8Bit都是QString转QByteArray的方法,Latin1代表ASCII,Local8Bit代表unicode