题目链接:

https://vjudge.net/problem/POJ-1195

题目大意:

直接维护二维树状数组

注意横纵坐标全部需要加1,因为树状数组从(1,1)开始

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<deque>
#include<sstream>
#include<cctype>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, s, t) for(int i = (s); i < (t); i++)
using namespace std;
typedef long long ll;
int T, n, m, cases;
int num[][];
int lowbit(int x)
{
return x & (-x);
}
///修改num[x][y] = d
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))
num[i][j] += d;
}
}
///计算顶点为(1, 1)(x, y)的数总和
int sum(int x, int y)
{
int ans = ;
for(int i = x; i > ; i -= lowbit(i))
{
for(int j = y; j > ; j -= lowbit(j))
ans += num[i][j];
}
return ans;
}
int main()
{
int t, x1, y1, x2, y2, d;
while(cin >> t >> n)
{
memset(num, , sizeof(num));
while(cin >> t)
{
if(t == )break;
else if(t == )
{
scanf("%d%d%d", &x1, &y1, &d);
x1++, y1++;
add(x1, y1, d);
}
else if(t == )
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1++, y1++, x2++, y2++;
cout<<(sum(x2, y2) - sum(x2, y1 - ) - sum(x1 - , y2) + sum(x1 - , y1 - ))<<endl;
}
}
}
return ;
}

POJ-1195 Mobile phones---裸的二维树状数组(注意下标从1,1开始)的更多相关文章

  1. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  2. 二维树状数组——SuperBrother打鼹鼠(Vijos1512)

    树状数组(BIT)是一个查询和修改复杂度都为log(n)的数据结构,主要用于查询任意两位之间的所有元素之和,其编程简单,很容易被实现.而且可以很容易地扩展到二维.让我们来看一道很裸的二维树状数组题: ...

  3. bzoj 1452: [JSOI2009]Count ——二维树状数组

    escription Input Output Sample Input Sample Output 1 2 HINT ———————————————————————————————————————— ...

  4. 二维树状数组+差分【p4514】上帝造题的七分钟

    Description "第一分钟,X说,要有矩阵,于是便有了一个里面写满了\(0\)的\(n\times m\)矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为\((a,b)\),右 ...

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

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

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

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

  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 二维树状数组

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

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

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

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

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

随机推荐

  1. Go语言基础之5--数组(array)和切片(slince)

    一.数组(array) 1.1 数组定义 1)含义: 数组是同一类型的元素集合. 数组是具有固定长度并拥有零个或者多个相同数据类型元素的序列. 2)定义一个数组的方法: var 变量名[len] ty ...

  2. 缓存算法及Redis、Memcached、Guava、Ehcache中的算法

    https://my.oschina.net/ffy/blog/501003 https://yq.aliyun.com/articles/622757 https://blog.csdn.net/s ...

  3. 16-----BBS论坛

    BBS论坛(十六) 16.登录功能完成 (1)front/forms.py class SigninForm(BaseForm): telephone = StringField(validators ...

  4. java——二分搜索树 BST(递归、非递归)

    ~ package Date_pacage; import java.util.Stack; import java.util.ArrayList; import java.util.LinkedLi ...

  5. linux解压大全

    .tar 解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)———————————————.gz解压1:gun ...

  6. (转)linux passwd批量修改用户密码

    linux passwd批量修改用户密码  原文:http://blog.csdn.net/xuwuhao/article/details/46618913 对系统定期修改密码是一个很重要的安全常识, ...

  7. LeetCode 167.两数之和(C++)

    给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明: 返回的下标值 ...

  8. rsync 命令中的路径斜线

    rsync命令大家都知道,但是其中的一个小细节比较容易被忽略,那就是 路径结尾的 "/" ,在路径的结尾有没有斜线,结果是大不同的.现举例说明: 假设现有两个目录,一个名为sour ...

  9. php7.0.24-nts配置步骤

    php-cgi.exe文件运行 php-cgi.exe -b 127.0.0.1:9000 -c D:/myphp2017/php7-nts/php.ini nginx命令 启动 start ngin ...

  10. Window WindowManager 和WindowManager.LayoutParams

    <一> Window window是android中的窗口,表示顶级窗口的意思,也就是主窗口,它有两个实现类, PhoneWindow和MidWindow,我们一般的activity对应的 ...