HDUOJ---2642Stars(二维树状数组)
Stars
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)
Total Submission(s): 975 Accepted Submission(s): 420
To make the problem easier,we considerate the sky is a two-dimension plane.Sometimes the star will be bright and sometimes the star will be dim.At first,there is no bright star in the sky,then some information will be given as "B x y" where 'B' represent bright and x represent the X coordinate and y represent the Y coordinate means the star at (x,y) is bright,And the 'D' in "D x y" mean the star at(x,y) is dim.When get a query as "Q X1 X2 Y1 Y2",you should tell Yifenfei how many bright stars there are in the region correspond X1,X2,Y1,Y2.
There is only one case.
each line start with a operational character.
if the character is B or D,then two integer X,Y (0 <=X,Y<= 1000)followed.
if the character is Q then four integer X1,X2,Y1,Y2(0 <=X1,X2,Y1,Y2<= 1000) followed.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 1005
#define lowbit(x) ((x)&(-x))
int aa[maxn][maxn];
bool bb[maxn][maxn]; void ope(int x,int y,int val)
{
int j;
if(val==)
{
if(bb[x][y]) return ;
bb[x][y]=true;
}
else
{
if(bb[x][y]==false)
return ;
bb[x][y]=false;
}
while(x<maxn){
j=y;
while(j<maxn){
aa[x][j]+=val;
j+=lowbit(j);
}
x+=lowbit(x);
}
}
int sum(int x,int y)
{
int ans= ,j;
while(x>){
j=y;
while(j>){
ans+=aa[x][j];
j-=lowbit(j);
}
x-=lowbit(x);
}
return ans;
}
struct node
{
int x;
int y;
};
int main()
{
int test,res;
char str[];
node a,b;
memset(aa,,sizeof(aa));
memset(bb,,sizeof(bb));
scanf("%d",&test);
while(test--)
{
scanf("%s",str);
if(str[]=='Q')
{
scanf("%d%d%d%d",&a.x,&b.x,&a.y,&b.y);
if(a.x>b.x){
a.x^=b.x;
b.x^=a.x;
a.x^=b.x;
}
if(a.y>b.y){
a.y^=b.y;
b.y^=a.y;
a.y^=b.y;
}
b.x++;
b.y++;
res=sum(b.x,b.y)-sum(a.x,b.y)+sum(a.x,a.y)-sum(b.x,a.y);
printf("%d\n",res);
}
else
{
scanf("%d%d",&a.x,&a.y);
a.x++; //ÓÒÒÆÒ»Î»
a.y++;
if(str[]=='B')
ope(a.x,a.y,);
else
ope(a.x,a.y,-);
}
}
return ;
}
HDUOJ---2642Stars(二维树状数组)的更多相关文章
- 二维树状数组 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)上的数全部 ...
- MooFest_二维树状数组
Description Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a s ...
随机推荐
- python文件目录操作
一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法.1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd()2.返回指定目录下的所有文件和目 ...
- 我们为什么以及是如何从 Angular.js 迁移到 Vue.js?
在我写这篇文章的时候,我们刚刚从我们的应用程序代码库中删除了最后一行AngularJS代码,结束了一个为期4个月的非侵入性工作,将我们的应用程序从AngularJS迁移到VueJS.在这篇文章中,我将 ...
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- Entity Framework泛型封装
Entity Framework本身的增删改查其实 已经很方便了,不过做项目的时候用的多了也就觉得有点累了,每个业务实体基本上都涉及到到了增删改查这四个基本的要素,至于封装每个公司可能都不一样,接口, ...
- 【Multiple backgrounds】用CSS3实现网页多重背景
对于背景属性background-image大家应该已经很熟悉了,在CSS2中与它相关的属性还有background-repeat(设置背景是否重复及重复的方式).background-positio ...
- 支持按行号区域文本选择的NotePad++插件开发
近期发现NotePad++不支持按行号区间的文本复制,就想自己动手开发一个NotePad++插件,支持输入起始行号和结束行号,然后复制该区域的文本到新文档或者拷贝到系统剪切板,方便文本的操作. 效果例 ...
- 【Hadoop】Combiner的本质是迷你的reducer,不能随意使用
问题提出: 众所周知,Hadoop框架使用Mapper将数据处理成一个<key,value>键值对,再网络节点间对其进行整理(shuffle),然后使用Reducer处理数据并进行最终输出 ...
- What's the difference between - (one hyphen) and — (two hyphens) in a command?
bash中看到这样的命令, curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - sudo apt-get install - ...
- 正则 js分转元带千分符号
可以通过缩放来进行分到元的转换,同时使用正则对处理后的数字进行千分位格式化 方法1:(不丢失精度) function Fen2Yuan( num ) { if ( typeof num !== &qu ...
- 使用Spring提供Quartz来实现定时任务
Spring功能越来越多了,用起来还很舒服方便,Quartz实现的定时任务就是一个. 首先是配置文件: <?xml version="1.0" encoding=" ...