与以往不同的是,这个树状数组是二维的,仅此而已

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
int n,c[][];
int lowbit(int k)
{
return k&(-k);
}
void add(int x,int y,int num)
{
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= n; j += lowbit(j))
c[i][j] += num; }
int cal(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 x;
scanf("%d",&x);
while(x--)
{
int t;
memset(c,,sizeof(c));
scanf("%d%d",&n,&t);
char op;
while(t--)
{
cin>>op;
if(op == 'C')
{
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
x1++,x2++,y1++,y2++;
add(x2,y2,);
add(x1-,y1-,);
add(x1-,y2,);
add(x2,y1-,);
}
else
{
int x,y;
scanf("%d%d",&x,&y);
//++x,++y
int ans = cal(x,y);// - cal(x-1,y-1) - cal(x-1,y) - cal(x,y-1);
ans %= ;
printf("%d\n",ans);
}
}
puts("");
}
return ;
}

POJ 2155 Matrix(二维树状数组)的更多相关文章

  1. POJ 2155 Matrix(二维树状数组,绝对具体)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Descripti ...

  2. poj 2155 Matrix (二维树状数组)

    题意:给你一个矩阵开始全是0,然后给你两种指令,第一种:C x1,y1,x2,y2 就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字全部翻转,0变1,1变0 第二种:Q x1 y1,输 ...

  3. POJ 2155:Matrix 二维树状数组

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 21757   Accepted: 8141 Descripti ...

  4. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  5. 【poj2155】Matrix(二维树状数组区间更新+单点查询)

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  6. POJ 2029 (二维树状数组)题解

    思路: 大力出奇迹,先用二维树状数组存,然后暴力枚举 算某个矩形区域的值的示意图如下,代码在下面慢慢找... 代码: #include<cstdio> #include<map> ...

  7. poj----2155 Matrix(二维树状数组第二类)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16950   Accepted: 6369 Descripti ...

  8. poj 2155 B - Matrix 二维树状数组

    #include<iostream> #include<string> #include<string.h> #include<cstdio> usin ...

  9. POJ2155:Matrix(二维树状数组,经典)

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  10. Matrix 二维树状数组的第二类应用

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17976   Accepted: 6737 Descripti ...

随机推荐

  1. String与string的区别

    在C#中,string 是 System.String 的别名,所以基本上在使用时是没有差别的. 习惯上,我们把字符串当作对象时(有值的对象实体),我们用string.而我们把它当类时(需要字符串类中 ...

  2. C++ 中 const和define的区别

    来源网址:http://wujiangping.blog.163.com/blog/static/195182011201255115125205/ 请区别用#define命令定义的符号常量和用con ...

  3. python zookeeper 在 uwsgi中 watcher不生效

    def code_watcher(handle,type, state, path):     print "zk code watcher,path is: ",path #da ...

  4. CentOS中由一般用户切换为root用户

    --->http://www.centoscn.com/CentOS/help/2014/0624/3173.html 1.打开终端,提示符为“$”,表明该用户为普通用户,此时,直接输su,回车 ...

  5. R语言笔记2--循环、R脚本

    1.循环语句 for语句 while语句 2.R脚本 source()函数 print()函数

  6. UIView animateWithDuration 使用详解

    在ios4.0及以后鼓励使用animateWithDuration方法来实现动画效果.当然,以往的begin/commit的方法依然使用,下面详细解释一下animateWithDuration的使用方 ...

  7. excel中自动变为插入语句的写法

    =concatenate("insert into t(b,c) values('",b1,"','",c1,"');")

  8. ueditor浏览器 无法上传文件.问题

    dll也都引用了 路径绝对tmd没问题 最后 我一点一点的调试发现了问题 草tmd百度程序员 */UE.ajax = function() { //创建一个ajaxRequest对象 var fnSt ...

  9. Winsock SPI-Socks5-SSL

  10. ado vb6

    http://www.cnblogs.com/ywb-lv/articles/2343444.html http://stackoverflow.com/questions/3334102/use-t ...