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 ...
随机推荐
- Java获取电脑IP、MAC、各种版本
Java代码获取电脑IP.MAC.各种版本 package com.rapoo.middle.action; import java.io.BufferedReader; import java.io ...
- 硬件负载均衡F5和软负责均衡Nginx
请直接搜索相关文章了解:http://www.ideadata.com.cn/wisdomAction/readWisdom.do?id=75 F5,硬件 优点:能够直接通过智能交换机实现,处理能 ...
- 【ContestHunter】【弱省胡策】【Round4】
01分数规划(网络流)+状压DP+树形DP 官方题解地址:http://pan.baidu.com/s/1mg5S5z6 A 好神啊= =第一次写01分数规划 其实分数规划是要求$$ Maximize ...
- 数学图形(1.45)毛雷尔玫瑰(Maurer rose)
毛雷尔玫瑰,也有的翻译是毛瑞尔,它是一种很漂亮的图形.玫瑰线的变异品种. 我没有找到其中文的解释,有兴趣可以看下维基上的相关页面. A Maurer rose of the rose r = sin( ...
- [10] 圆管(Pipe)图形的生成算法
顶点数据的生成 bool YfBuildPipeVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, YeO ...
- 网站日志访问记录组件UserVisitLogsHelp开源了!
之前在<一种基于自定义代码记录用户访问日志在Sharepoint网站的应用方法!>一文利用本人几年前的开发的UserVisitLogsHelp组件进行了网站用户访问日志记录,可用于网站分析 ...
- 【SpringCloud】Netflix源码解析之Ribbon:负载均衡策略的定义和实现
Ribbon负载均衡策略定义 IRule其实就只做了一件事情Server choose(Object key),可以看到这个功能是在LB中定义(要求)的,LB把这个功能委托给IRule来实现.不同的I ...
- IDA远程调试so库JNI_Onload函数
JNI_OnLoad函数大概功能就是在程序加载so的时候,会执行JNI_OnLoad函数,做一系列的准备工作.很多时候,程序猿们会将一些重要信息放在此函数中,而不是通过某种事件来重复触发.包括说将反调 ...
- supervisord不重启更新配置文件
二.更新新的配置到supervisord supervisorctl update 1 三.重新启动配置中的所有程序 supervisorctl reload
- json数据的用法
json数据在后台跟前台传递数据使用是非常多站点开发者再熟悉只是的数据格式了,可是呢在这之前肯定有不少人还不知道json数据是怎么使用的, {"name":"01&quo ...