题目链接:传送门

题意:给出操作,按照操作进行。

思路:将树状数组设置为二维的就行了。

注意:

(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(二维树状数组)的更多相关文章

  1. POJ 1195 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18489   Accepted: 8558 De ...

  2. Mobile phones POJ - 1195 二维树状数组求和

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  3. poj 2029 二维树状数组

    思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...

  4. poj 3378 二维树状数组

    思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...

  5. poj 2155 (二维树状数组 区间修改 求某点值)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33682   Accepted: 12194 Descript ...

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

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

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

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

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

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

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

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

随机推荐

  1. jakson

    Java下常见的Json类库有Gson.JSON-lib和Jackson等,Jackson相对来说比较高效,在项目中主要使用Jackson进行JSON和Java对象转换,下面给出一些Jackson的J ...

  2. @RequestParam使用须知

    --------------------------siwuxie095                             @RequestParam 使用须知         使用 @Requ ...

  3. elasticsearch查询语句总结

    query 和  filter 的区别请看:https://www.cnblogs.com/bainianminguo/articles/10396956.html Filter DSL term 过 ...

  4. java Scanner类注意事项

    1,循环或递归调用获取数字时,不能用hasNextInt()判断是否有输入,不然会陷入死循环,应该用hasNext().获取也不能用nextInt(),应用next(),否则也会死循环 例如这段代码, ...

  5. golang语言中os包的学习与使用(文件,目录,进程的操作)

    os中一些常用函数的使用: package main; import ( "os" "fmt" "time" "strings&q ...

  6. Excel怎么下拉框多选

    打开Exlce, 确定,然后 右击查看代码,把这段代码复制到新建的文件里面 此时Excel会给出提示,选择否,,系统会提示保存,在保存的时候选择启用宏的工作簿然后保存,此时Excel下拉框多选就搞定了 ...

  7. SQL新增数据取表主键最新值

    string strsql = "insert into SB_Survey(title) values ('标题');select @@IDENTITY"; int s = in ...

  8. Windows Live Writer

    一.简介 Windows Live Writer 是一个强大的离线博客编辑工具,通过它可以离线编辑内容丰富的博文,除了自身强大的编辑功能之外,还提供了接口,让其它开发人员通过插件提供工具自身没有提供的 ...

  9. Attribute Syntax

    Attribute Syntax This section describes the syntax with which __attribute__ may be used, and the con ...

  10. PAT 甲级 1005 Spell It Right (20)(代码)

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...