二维树状数组(HD2642)
#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)的更多相关文章
- 二维树状数组 BZOJ 1452 [JSOI2009]Count
题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...
- HDU1559 最大子矩阵 (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) ...
- POJMatrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 22058 Accepted: 8219 Descripti ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- 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 ...
- POJ 2155 Matrix(二维树状数组+区间更新单点求和)
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
- POJ 2155 Matrix (二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17224 Accepted: 6460 Descripti ...
- [POJ2155]Matrix(二维树状数组)
题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...
随机推荐
- linux学习笔记之IO
一.基础知识. 1:普通IO类型. 1,非阻塞IO:发出open/read/write等IO操作,并使这些操作不会永远阻塞.当不能完成时,会立即出错返回. 1)非阻塞的两种标志方式:指定标志:O_NO ...
- Go 语言读写 Excel
Excelize 是 Golang 编写的一个用来操作 Office Excel 文档类库,基于微软的 Office OpenXML 标准.可以使用它来读取.写入 XLSX 文件.相比较其他的开源类库 ...
- SQL Server中的PWDENCRYPT与PWDCOMPARE函数
前幾天有個客戶的網站出問題(不是我們開發的),請我們幫他看,主要的問題是他們的網站會員在進行查詢密碼時,會員收到信的時候在密碼的欄位竟然會出現 System.Binary[] 字樣.而我進去資料庫中查 ...
- .NET4.0下使用Net2.0类库或程序集
最近在项目上一直使用.net4.0 framework,使用ffmepeg下的一个dll时,提示只能在2.0下运行,解决方法如下: app.config中添加一个配置节:startup <?xm ...
- 【原创】QT5-卸载精灵v1.0-卸载windows软件-简易版
由于项目需求,需要实现卸载windows上的普通软件的小功能,实现起来还是比较简单的. 先发个图: 思路: 1.根据注册表的信息去打开应用程序,卸载也一样: 2.读桌面的快捷方式,根据快捷方式的指向路 ...
- 转:C4项目中验证用户登录一个特性就搞定
转:C4项目中验证用户登录一个特性就搞定 在开发过程中,需要用户登陆才能访问指定的页面这种功能,微软已经提供了这个特性. // 摘要: // 表示一个特性,该特性用于限制调用 ...
- Counting square
Problem Description There is a matrix of size R rows by C columns. Each element in the matrix is eit ...
- 关于mwArray和一般数组的区别
可以用下面的代码详细理解mwArray和一般数组之间的区别 mwArray a(, , mxDOUBLE_CLASS); double *aData; aData = ]; int iii; ; ii ...
- 【LeetCode练习题】Multiply Strings
Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a ...
- OpenStack Block Storage安装配置use LVM
1,storage systems use LVM Ins and configuration Block Storage; apt-get install lvm2; 创建Physical volu ...