二维的树状数组,,,

记得矩阵的求和运算要想好在写。。。。

代码如下:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <map> #define M 1100
#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define LLU unsigned long long
#define lowbit(x) (x&-x) using namespace std; LL c[M][M];
int n;
void add(int x, int y, int a)
{
for(int i = x; i <= n; i+=lowbit(i))
for(int j = y; j <= n; j+=lowbit(j))
c[i][j] += a;
}
LL sum(int l, int r, int ll, int rr)
{
LL s1 = 0;
for(int i = l-1; i > 0; i-=lowbit(i))
for(int j = r-1; j > 0; j -= lowbit(j))
s1+=c[i][j];
LL s2 = 0;
for(int i = l-1; i > 0; i-=lowbit(i))
for(int j = rr; j > 0; j -= lowbit(j))
s2+=c[i][j];
LL s3 = 0;
for(int i = ll; i > 0; i-=lowbit(i))
for(int j = r-1; j > 0; j -= lowbit(j))
s3+=c[i][j];
LL s = 0;
for(int i = ll; i > 0; i-=lowbit(i))
for(int j = rr; j > 0; j-=lowbit(j))
s+=c[i][j];
return s+s1-s2-s3;
}
int main ()
{
int t, x, y, a, l, r, ll, rr;
scanf("%d%d", &t, &n);
while(scanf("%d", &t), t!=3)
{
if(t==1)
{
scanf("%d%d%d", &x, &y, &a);
add(x+1, y+1, a);
}
else
{
scanf("%d%d%d%d", &l, &r, &ll, &rr);
printf("%lld\n", sum(l+1, r+1, ll+1, rr+1));
}
}
return 0;
}

poj 1195 - Mobile phones(树状数组)的更多相关文章

  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 1195:Mobile phones(二维树状数组,矩阵求和)

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

  4. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

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

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

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

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

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

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

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

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

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

    偶然发现这题还没A掉............速速解决了............. 树状数组和线段树比较下,线段树是在是太冗余了,以后能用树状数组还是尽量用......... #include < ...

随机推荐

  1. 转一下大牛的嵌入web页播放视频方法(转)

    来自:http://www.cnblogs.com/bandry/archive/2006/10/11/526229.html 在Web页中嵌入Media Player的方法比较简单,只要用HTML中 ...

  2. css之absolute绝对定位(绝对定位特性)

    学习了绝对定位以后,对此进行一个总结,啦啦啦啦~ 绝对定位特性 1.破坏性 破坏了原有的位置,从文档流里脱离出来 2.包裹性 如果下面这种情况,父级元素将不会有高度和宽度,失去原有的大小

  3. [刘阳Java]_避开环境配置快速的使用Java的开发工具_第5讲

    我们一般学习Java都应该遵循通过系统的命令工具来编译Java程序,然后对编译好Java程序进行运行,这个是非常好的习惯.但是随着后期学习Java技术的深入我们也得像Java的IDE工具屈服.所以,可 ...

  4. js正则获取图片的src属性及正则分割一个字符串

    try{     var str='<P>xczxzxzxcxcxc<IMG src="http://file.ynet.com/2/1612/12/12119048.jp ...

  5. 关于spring boot jar包与war包的问题

    此文为转载:http://mrlee23.iteye.com/blog/2047968 在开发调试完成之后,可以将应用打成JAR包的形式,在Eclipse中可以直接使用Maven插件的package命 ...

  6. 使用kindeditor文本编辑器

    aspx中代码: <%@ Page Language="C#" ValidateRequest="false" AutoEventWireup=" ...

  7. mb_系列函数和普通字符函数的区别

    <?php //phpinfo(); $str = 'abcdef'; echo strlen($str);// 6 echo '<br/>'; echo substr($str, ...

  8. NOIP注意事项

    高精度 a.加法 b.减法 c.乘法(应该只会有高精乘单精)                                d.高精度除单精                 (后面c,d考的可能性较小 ...

  9. android 获取系统联系人 完全解析

    一.代码 1.ContactsEngine.java import java.util.ArrayList; import java.util.HashMap; import java.util.Li ...

  10. Spring 4 官方文档学习 Spring与Java EE技术的集成

    本部分覆盖了以下内容: Chapter 28, Remoting and web services using Spring -- 使用Spring进行远程和web服务 Chapter 29, Ent ...