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

#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. tableview cell添加3D动画

    当cell显示之前,会先调用该方法,因此给cell添加动画,在这个方法里面即可. -(void)tableView:(UITableView *)tableView willDisplayCell:( ...

  2. java方法中只有值传递,没有引用传递

    public class Example { String testString = new String("good"); char[] testCharArray = {'a' ...

  3. HAProxy与varnish

    Even if HAProxy can do TCP proxying, it is often used in front of web application, exactly where we ...

  4. 去掉uitableveiw多余的分割线

    UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [_tableView setTableFooterView:v];

  5. ASP.NET 会话状态的模式

    ASP.NET 会话状态为会话数据提供了几个不同的存储选项.每个选项都通过一个 SessionStateMode 枚举值进行识别.如下列表中描述了可用的会话状态模式: InProc 模式:把会话状态存 ...

  6. MySQL 视图 总结

    什么是视图 视图是从一个或多个表中导出来的表,是一种虚拟存在的表. 视图就像一个窗口,通过这个窗口可以看到系统专门提供的数据. 这样,用户可以不用看到整个数据库中的数据,而之关心对自己有用的数据. 数 ...

  7. cocos2d-x 不规则形状按钮的点击判定

    cocos2d-x 不规则形状按钮的点击判定 原理: 1.OpeGL ES提供了glReadPixels[^footnote]函数,来获取当前framebuffer上的像素数据 2.cocos2d-x ...

  8. Windows任务管理器中内存使用、虚拟内存区别及与页面文件的关系

    原文地址:Windows任务管理器中内存使用.虚拟内存区别及与页面文件的关系 虚拟内存(VirtualMemory)是Windows管理所有可用内存的方式.对于32位Windows系统,每个进程所用到 ...

  9. hdu1950 Bridging signals 最长递增子序列

    用一个数组记下递增子序列长度为i时最小的len[i],不断更新len数组,最大的i即为最长递增子序列的长度 #include<cstdio> #include<algorithm&g ...

  10. php过滤HTML标签、属性等正则表达式汇总

    $str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ] ...