poj-1195(二维树状数组)
题目链接:传送门
题意:给出操作,按照操作进行。
思路:将树状数组设置为二维的就行了。
注意:
(1)每次求出的面积是S(x2,y2)-S(x1-1,y2)-S(x2,y1-1)+S(x1-1,y1-1)。
(2)树状数组的lowbit不允许0。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = ;
int c[maxn][maxn],lowbit[maxn],N;
void update(int x,int y,int Item)
{
for(int i=x;i<=N;i+=lowbit[i])
for(int j=y;j<=N;j+=lowbit[j])
c[i][j]+=Item;
}
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 get_ans(int x,int y,int A,int B)
{
return query(A+,B+)+query(x,y)-query(x,B+)-query(A+,y);
}
int main(void)
{
int i,j,x,y,A,B,pos;
for(i=;i<maxn;i++) lowbit[i]=i&(-i);
while()
{
scanf("%d",&pos);
if(pos==)
{
scanf("%d%d%d",&x,&y,&A);
update(x+,y+,A);
}
else if(pos==)
{
scanf("%d%d%d%d",&x,&y,&A,&B);
int ans=get_ans(x,y,A,B);
printf("%d\n",ans);
}
else if(pos==)
{
scanf("%d",&N);
memset(c,,sizeof(c));
}
else break;
}
return ;
}
poj-1195(二维树状数组)的更多相关文章
- POJ 1195 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18489 Accepted: 8558 De ...
- Mobile phones POJ - 1195 二维树状数组求和
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- poj 2029 二维树状数组
思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- poj 3378 二维树状数组
思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...
- poj 2155 (二维树状数组 区间修改 求某点值)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33682 Accepted: 12194 Descript ...
- 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【二维树状数组】
<题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...
- 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 ...
随机推荐
- 控制台输出到txt
//PrintStream 为其他输出流添加了功能,使它们能够方便地打印各种数据值表示形式. //PrintStream不同于PrintWriter,PrintStream输出的是字节内容. //pu ...
- Delphi异步编程:匿名线程与匿名方法
异步编程,是项目中非常有用的而且常用的一种方法,大多以线程实现. 而Delphi传统方法使用线程略为烦琐,好在其后续版本中,提供一些方法,简化一些操作. 几个概念: 匿名线程:TAnonymousTh ...
- crm作业知识点集合[一]
知识点1 1.当我们通过model建立一对多或者多对多的关系的时候,默认情况下,会关联所有的字段,如果我们使用djanog的forms的话,可以加一个属性,限制我这个字段只关联哪些字段,就是用下面的写 ...
- python3之subprocess常见方法使用
一.常见subprocess方法 1.subprocess.getstatusoutput(cmd) 官方解释: Return (exitcode, output) of executing cmd ...
- 再遇ibatisNet
11年在Mr刘的带领下第一次接触ibatisnet ,当时Mr刘很详细的很讲了xml里的写法还有配置文件之类的,但是随着时间越来越久远.很多东西都开始淡忘了. 如今,再次和它相遇,依然觉得很亲切,虽然 ...
- VS unable to update auto-refresh path。。。。
手工创建提示报错的路径,重新生成,成功
- SHA1加密工具
package com.wx.project.util; import java.security.MessageDigest; /* * sha1 加密算法 * 网上copy 一大堆 */ publ ...
- linux命令学习之:ps
Linux中的ps命令是Process Status的缩写.ps命令用于报告当前系统的进程状态,列出系统中当前运行的那些进程.可以搭配kill指令随时中断.删除不必要的程序. 要对进程进行监测和控制, ...
- centos7下apache2.4反向代理
apache安装目录在/data/apache24,这里就不介绍apache的安装了. 一.反向代理配置 在/data/apache24/conf/extra下创建htttpd-proxy.conf文 ...
- 【gRPC使用问题3】生成出来无法识别Google.Api.AnnotationsReflection.Descriptor
1.问题截图: 2.解决方案: Install the package "Google.Api.Gax.Grpc". From the Package Manager Consol ...