题目链接:传送门

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

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

注意:

(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. 模板】AC自动机(简单版)

    模板]AC自动机(简单版) https://www.luogu.org/problemnew/show/P3808 这是一道简单的AC自动机模板题. 用于检测正确性以及算法常数. 为了防止卡OJ,在保 ...

  2. zkClient的使用

    ZKClient是由DataMeer的工程师StefanGroschupf和Peter Voss 一起开发的,在源生API接口基础上进行了封装,简化了ZK的复杂性. 1. 创建客户端方法:ZKClie ...

  3. 【linux C】C语言中常用的几个函数的总结【二】

    3.fgets 虽然用 gets() 时有空格也可以直接输入,但是 gets() 有一个非常大的缺陷,即它不检查预留存储区是否能够容纳实际输入的数据,换句话说,如果输入的字符数目大于数组的长度,get ...

  4. Myeclipse安装完配置

    1.Window --> preferences --> 搜索tomcat --> Tomcat7.x --> 选择Enable并导入tomcat所在目录2.Window -- ...

  5. java 线程Thread 技术--线程创建源码解释

    永远不要忘记最基础的东西,只有把最基础的知识打牢靠,才能够使你走的更远,我将从今天开始,进行线程知识的回顾,一些常用知识点,以及java1.5 引入的并发库,进行详细的讲解与总结 创建线程的目的是为了 ...

  6. Mysql在Linux的基本操作文档

    总结了Mysql在Linux下的应用,以下是Linux操作系统操作MySQL常用命令小结,需要的朋友参考下: 1.Mysql服务 # chkconfig --list 列出所有系统服务 # chkco ...

  7. linux操作Mysql数据库基本命令

    1.显示数据库 show databases; 2.选择数据库 use 数据库名; 3.显示数据库中的表 show tables; 4.显示数据表的结构 describe 表名; 5.显示表中记录 S ...

  8. IntelliJ IDEA return null with ClassLoader.getSystemResourceAsStream(“configFilename”));

    参考https://stackoverflow.com/questions/49470053/intellij-idea-return-null-with-classloader-getsystemr ...

  9. webstorm打开一个门户工程流程

    1.电脑上安装了nginx   ,进入conf目录下,找到nginx.conf打开 2.将原配置中server部分替换掉 server{ listen       80;     server_nam ...

  10. css代码插入三种方式

    1.内联式 <p style="color:red;font-size: 12px">iutt</p> 2.嵌入式 <style type=" ...