#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std; #define BITMAX 1002 //数组大小
typedef int valueType; //元素类型定义
valueType BITree[BITMAX][BITMAX]; //二维树状数组,初始化
/* 2^k k表示节点编号 x 二进制末尾 0 的个数 */
inline int lowbit(int x)
{
return x & (-x);
} /* 节点编号不能为 0 */
/* 二维 C[x][y] = sum(A[i][j]) 其中,x-lowbit[x]+1 <= i<=x 且 y-lowbit[y]+1 <= j <=y */
inline void addPoint(int x, int y, valueType add, int n)
{
for (int i = x; i <= n; i += lowbit(i))
for (int j = y; j <= n; j += lowbit(j))
BITree[i][j] += add;
}
inline valueType readSum(int x, int y)
{
valueType sum = ;
for (int i = x; i > ; i -= lowbit(i))
for (int j = y; j > ; j -= lowbit(j))
sum += BITree[i][j];
return sum;
} bool f[BITMAX][BITMAX];
int main()
{
int m;
char cc[];
int a, b, c, d;
scanf("%d", &m);
memset(BITree, , sizeof(BITree));
memset(f, false, sizeof(f));
while (m--){
scanf("%s", &cc);
switch (cc[])
{
case 'B':
scanf("%d %d", &a, &b);
++a; ++b;
if (f[a][b]) break;
addPoint(a, b, , BITMAX);
f[a][b] = true;
break;
case 'D':
scanf("%d %d", &a, &b);
++a; ++b;
if (f[a][b]) addPoint(a, b, -, BITMAX);
f[a][b] = false;
break;
case 'Q':
scanf("%d %d %d %d", &a, &b, &c, &d);
++a; ++b; ++c; ++d;
if (a > b) swap(a, b);
if (c > d) swap(c, d);
printf("%d\n", readSum(b, d) - readSum(b, c - ) - readSum(a - , d) + readSum(a - , c - ));
break;
default:
break;
}
}
}

二维树状数组(HD2642)的更多相关文章

  1. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  2. HDU1559 最大子矩阵 (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)  ...

  3. POJMatrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Descripti ...

  4. poj 1195:Mobile phones(二维树状数组,矩阵求和)

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

  5. Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*

    D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this prob ...

  6. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

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

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

  8. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  9. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

随机推荐

  1. Oprofile安装与使用探索

    本文分别尝试了oprofile在x86平台和龙芯平台上的安装 一:oprofile的安装与配置(intel+ubuntu12.04) I. Oprofile 安装 Oprofile 包含在 Linux ...

  2. JQ----树杈型导航

    简单的做了一个树杈型的导航结构如下所示: 废话不多说,上代码: HTML: <div class="wrapper"> <div class="tabt ...

  3. ecshop简单结构

    Ecshop包括的文件夹有admin.api.cert.data.images.includes.js. languages.plugins.temp.theme.wap.widget这些文件夹,和根 ...

  4. php 格式

    $abc = ($_POST[' : strtotime($_POST['start_time']); 解析:判断接收的数据是否为0,如果等于0赋值0,若不等于,则赋值获取的数值. strtotime ...

  5. win32 调用多媒体函数PlaySound()

    必须引入此头文件 #include <mmsystem.h>#pragma comment(lib, "WINMM.LIB") /*------------------ ...

  6. 入门指引 - PHP手册笔记

    曾经简单的学习过PHP,看的是<PHP和MySQL Web开发>,还有万能的搜索引擎的帮助.这次准备系统的学习一下,参考资料是PHP Manual. PHP能做什么 PHP主要用于服务端的 ...

  7. SQL Server 查看表定义的 2 种方法

    方法 1. 用SQL Server Management Studio 第一步找到要查看的表,右键 第二步点设计 方法 2. sp_help @objname = 'tableName' execut ...

  8. 关于SubclassWindow()和SubclassDlgItem

    msdn上的解析 CWnd::SubclassWindowBOOL SubclassWindow( HWND hWnd ); Return Value Nonzero if the function ...

  9. 为什么不能在scrollview中直接添加一个image,然后使animation.begin()??

    http://stackoverflow.com/questions/17267451/animation-cant-begin-in-scrollview-in-windows-phone 以上是我 ...

  10. HDU1875 畅通工程再续 (并查集)

    畅通工程再续 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...