POJ-1195 Mobile phones---裸的二维树状数组(注意下标从1,1开始)
题目链接:
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开始)的更多相关文章
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
- 二维树状数组——SuperBrother打鼹鼠(Vijos1512)
树状数组(BIT)是一个查询和修改复杂度都为log(n)的数据结构,主要用于查询任意两位之间的所有元素之和,其编程简单,很容易被实现.而且可以很容易地扩展到二维.让我们来看一道很裸的二维树状数组题: ...
- bzoj 1452: [JSOI2009]Count ——二维树状数组
escription Input Output Sample Input Sample Output 1 2 HINT ———————————————————————————————————————— ...
- 二维树状数组+差分【p4514】上帝造题的七分钟
Description "第一分钟,X说,要有矩阵,于是便有了一个里面写满了\(0\)的\(n\times m\)矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为\((a,b)\),右 ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- POJ 1195 Mobile phones【二维树状数组】
<题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
随机推荐
- HttpClient,Socket,URL知识
java中: tip/ip , udp 传输协议 网络编程有三大类:Socket,URL,datagram HTTP协议是建立在TCP协议之上的一种应用. 一:HttpClient HttpCli ...
- Juniper SRX550防火墙web页面CPU达到100%的故障解决办法
Juniper SRX550防火墙web页面CPU达到100%的故障解决办法 利用telnet远程连接主机,对web页面注销重新登录即可,在配置中输入命令:run restart web-manage ...
- n阶乘,位数,log函数,斯特林公式
一.log函数 头文件: #include <math.h> 使用: 引入#include<cmath> 以e为底:log(exp(n)) 以10为底:log10(n) 以m为 ...
- Vue循环中多个input绑定指定v-model
Vue.js中提供了v-model可以双向绑定表单元素,这个方法可以非常方便的获得输入的值,但是有时候表单元素需要循环生成,在循环中要怎样获得指定输入框的值呢 这里介绍两种,一种是v-for中循环生成 ...
- 数据库版本管理工具flyway
引入flyway_core jar包 java 代码实现 public class FlywayMigration { @Resource private DataSource dataSource ...
- jemalloc报 Unsupported system page size错误
- python单元测试框架-unittest(四)之用例综合框架管理
简述为何如要框架? 前面测试用例与执行都是写在一个文件,当用例数量不断增加的时候,用例的执行与管理变得非常麻烦,因此需要对用例根据具体的功能模块来使用单独的模块来管理.就像一所学校要根据不同年级进行分 ...
- Nginx实践:(1) Nginx安装及日志配置
1. 安装 (1) Nginx下载地址:https://nginx.org/download/nginx-1.14.0.tar.gz (2) 安装时可能出现依赖库不存在,比如prec包,可以使用y ...
- Powershell(3)
Powershell 可以使用powershell管理的服务 share point, exchange, lync, windows azure, window server, system cen ...
- 基础7 面向对象进阶与socket编程
1.静态方法(用得少)(解除某个函数跟类的关联,加了静态方法后,类便不能将类的参数传给静态方法函数了) class Dog(object): def __init__(self,name): @sta ...