【题意】给你一个矩阵(初始化为0)和一些操作,1 x y a表示在arr[x][y]加上a,2 l b r t 表示求左上角为(l,b),右下角为(r,t)的矩阵的和。

【思路】帮助更好理解树状数组。

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=;
int c[N][N];
int s;
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int a)
{
for(int i=x;i<=s;i+=lowbit(i))
{
for(int j=y;j<=s;j+=lowbit(j))
{
c[i][j]+=a;
}
}
}
int get_sum(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 main()
{
int ins;
int x,y,a;
int l,b,r,t;
while(scanf("%d",&ins))
{
if(ins==)
{
scanf("%d",&s);
memset(c,,sizeof(c));
}
else if(ins==)
{
scanf("%d%d%d",&x,&y,&a);
update(x+,y+,a);
}
else if(ins==)
{
scanf("%d%d%d%d",&l,&b,&r,&t);
l++,b++,t++,r++;
printf("%d\n",get_sum(r,t)+get_sum(l-,b-)-get_sum(r,b-)-get_sum(l-,t));
}
else break;
}
return ;
}

Mobile phones_二维树状数组的更多相关文章

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

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

  2. 【poj1195】Mobile phones(二维树状数组)

    题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...

  3. poj 1195 Mobile phones(二维树状数组)

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

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

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

  5. 【POJ1195】【二维树状数组】Mobile phones

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

  6. (简单) POJ 1195 Mobile phones,二维树状数组。

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

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

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013912596/article/details/33802561 题目链接:id=1195&qu ...

随机推荐

  1. hdu 2473 Junk-Mail Filter (并查集之点的删除)

    Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. hdu----(1257)最少拦截系统(dp/LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. 判断jQuery元素是否隐藏

    第一种:使用CSS属性 复制代码 代码如下: var display =$('#id').css('display'); if(display == 'none'){    alert("被 ...

  4. arrow css

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 源代码解读Cas实现单点登出(single sign out)功能实现原理

    关于Cas实现单点登入(single sing on)功能的文章在网上介绍的比较多,想必大家多多少少都已经有所了解,在此就不再做具体介绍.如果不清楚的,那只能等我把single sign on这块整理 ...

  6. linux系统字符集

    Linux中中文乱码问题通常是由于字符集与windows不兼容所引起,windows的中文字符集是双字节的GBK编码linux采用的是3字节的utf-8编码,所以在windows下用工具连接linux ...

  7. setsockopt的作用

    功能描述:        获取或者设置与某个套接字关联的选 项.选项可能存在于多层协议中,它们总会出现在最上面的套接字层.当操作套接字选项时,选项位于的层和选项的名称必须给出.为了操作套接字层的选项, ...

  8. hdu 4632 Palindrome subsequence

    http://acm.hdu.edu.cn/showproblem.php?pid=4632 简单DP 代码: #include<iostream> #include<cstdio& ...

  9. Redis系列-存储篇set主要操作函数小结

    最近,总是以“太忙“为借口,很久没有blog了,凡事贵在恒,希望我能够坚持不懈,毕竟在blog的时候,也能提升自己.废话不说了,直奔主题”set“ redis set 是string类型对象的无序集合 ...

  10. Rhel6-mailsystem配置文档

    (postfix+dovecot+mysql+extmail) 理论基础: