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 ...
随机推荐
- Reportviewer中的函数使用——打印当前日期并格式化
如2017-10-23 12:20:20 通过DateTime.Now.ToString("yyMMddHHmmss")变为 20171023122020字符串
- 安装tensorflow ubuntu18.04
1.首先安装环境是ubuntu18.04. $sudo apt-get install python-pip python-dev python-virtualenv2.安装virtualenv虚拟环 ...
- crm作业知识点集合[三]
知识点1 我们要实现一个这样的功能,在学生表中,可以查看每个学生的报名的班级的所有的成绩,就是下图的效果 1.首先我们需要在学生表中自定义一列,这一列的内容就是一个a标签,指向另外一个页面,而我们在另 ...
- day 18 类,对象
类,对象: 类 具有相似功能的一类事物,人类,犬类,猫类等等. 对象: 类的具体表现 面向对象: 1.第一个优点:面向对象是一类相似功能函数的集合体 更清晰化,更规范化 class LoginHand ...
- Mysql的随机抽取
方法一 SELECT * FROM SHARE ORDER BY RAND( ) LIMIT 1; 在MYSQL的官方手册,里面针对RAND()的提示大概意思就是,在ORDER BY从句里面不能使用R ...
- Failed to read artifact descriptor for xxx:jar的问题解决
在开发的过程中,尤其是新手,我们经常遇到Maven下载依赖jar包的问题,也就是遇到“Failed to read artifact descriptor for xxx:jar”的错误. 对于这种非 ...
- mysql 事务中如果有sql语句出错,会导致自动回滚吗?
事务,我们都知道具有原子性,操作要么全部成功,要么全部失败.但是有可能会造成误解. 我们先准备一张表,来进行测试 CREATE TABLE `name` ( `id` int(11) unsigned ...
- 9.14 h5日记
9.14 ❤知识补充 margin的问题:margin:0 auto:可以解决元素在网页的居中问题(记得设置宽度) 1.css层叠样式表的问题 CSS的两个性质 (1)继承性 (2)层叠性 ...
- html标签一
<body></body> 网页内容 <p></p>段落 <h1></h1> ----<h6></h6> ...
- android时间选择器(API13以上)
public class UnloadCargoFragment extends Fragment implements OnClickListener { private View rootView ...