二维的树状数组,,,

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

代码如下:

#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. C#实现简单的委托异步调用

    delegate void textAsy(); static void Main(string[] args) { textAsy t = texts; AsyncCallback callBack ...

  2. bwa用法

    一 建立索引 比对之前,需要对fasta文件构建FM-index索引:bwa index -a bwtsw hg19.fasta 生成 hg19.fasta.amb.hg19.fasta.ann.hg ...

  3. java javacv调用摄像头并拍照

    调用摄像头并拍张照片,我一开始用的java的jmf媒体框架,但这个有很多的局限性不好使并且很有麻烦,兜了一圈发现javacv东西,研究之后这东西简单,方便:废话不多说了来重点. javacv官网:点击 ...

  4. [Notes] AWS Automation using script and AWS CLI

    (c) 2014 Amazon Web Services, Inc. and its afflialtes, All rights reserved. The content in this file ...

  5. QT5.2.1大BUG

    本来以为5.2.1是release版本 谁知道编译某个程序,执行老是crash 换5.3.2就ok了. 坑啊

  6. 关于Linkedlist 和 ArrayDeque的讨论

    转自:http://blog.csdn.net/f2006116/article/details/51375470 其中:我们要讨论的LinkedList和ArrayDeque都是实现Deque接口, ...

  7. effetive C++ 02 尽量以const,enum,inline替换#define

    #define ASPECT_RATIO=1.1const double AspectRatio=1.1 1. 使用宏会导致预处理器把程序代码中的ASPECT_RATIO无条件替换为1.1,编译器从未 ...

  8. Shell使用技巧

    巧用定界符delimiter 输入大段文本的地方 自动选择和输入的地方 访问数据库 Angel@DESKTOP-254LBLA ~ $ cat > out.txt << EOF &g ...

  9. mysql 主从不同步

    今天发现Mysql的主从数据库没有同步 先上Master库: mysql>show processlist; 查看下进程是否Sleep太多.发现很正常. show master status; ...

  10. [Gnu]Centos7 解决 gdb 提示 Missing separate debuginfos

    Centos7 上使用gdb: $ gdb php $ run /home/www/2.php 运行完 run,后面跟着很长的提示: …. Missing separate debuginfos, u ...