二维的树状数组,,,

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

代码如下:

#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. 【译】RabbitMQ:工作队列(Work Queue)

    在第一篇我们写了两个程序通过一个命名的队列分别发送和接收消息.在这一篇,我们将创建一个工作队列在多个工作线程间分发耗时的工作任务. 工作队列的核心思想是避免立刻处理资源密集型任务导致必须等待其执行完成 ...

  2. MBProgressHud添加自定义动画

    在使用自定义view时,若直接使用,如下 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud ...

  3. JS之BOM、客户端检测和DOM

    这是第八章到第十二章的内容,粗略浏览过一遍. 一.BOM 浏览器对象模型.包括了window.location.navigator.screen和history对象. window:核心对象 1.JS ...

  4. 合并两个排好序的链表(c++)

    #include<iostream> struct node{ int payload; node* next; node(int payload){this->payload=pa ...

  5. c# datagridview 中DataSource的使用总结

    由于当前项目的窗体更新使用的是订阅事件的方式.其中有个datagridview 动态显示统计数据的列表框.本来想用textbox显示,但不规则,看起来也不美观,改由dgv显示. 我没打算用改dgv表的 ...

  6. Java 内部类摘抄

    关于Java的内部类,要说的东西实在太多,这篇博文中也无法一一具体说到,所以就挑些重点的讲.关于内部类的使用,你可能会疑问,为什么我们要使用内部类?为了回答这个问题,你需要知道一些关于内部类的重点.所 ...

  7. Linux添加/删除用户和用户组

    声明:现大部分文章为寻找问题时在网上相互转载,在此博客中做个记录,方便自己也方便有类似问题的朋友,故原出处已不好查到,如有侵权,请发邮件表明文章和原出处地址,我一定在文章中注明.谢谢. 本文总结了Li ...

  8. Python中的threading

    Python中的threading RLock--重入锁 RLock在Python中的实现是对Lock的封装,具体在类中维护了一个重入次数的变量.一旦一个线程获得一个RLock,该线程再次要求获得该锁 ...

  9. NPOI导出Excel(含有超过65335的处理情况)

    NPOI导出Excel的网上有很多,正好自己遇到就学习并总结了一下: 首先说明几点: 1.Excel2003及一下:后缀xls,单个sheet最大行数为65335 Excel2007 单个sheet ...

  10. 【Java学习笔记】其他对象API

    System类 package p1; import java.util.Properties; import java.util.Set; public class SystemDemo { pri ...