Stars

Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)
Total Submission(s): 111 Accepted Submission(s): 54
 
Problem Description
Yifenfei is a romantic guy and he likes to count the stars in the sky.
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.

 
Input
The first line contain a M(M <= 100000), then M line followed.
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.
 
Output
For each query,output the number of bright stars in one line.
 
Sample Input
5
B 581 145
B 581 145
Q 0 600 0 200
D 581 145
Q 0 600 0 200
 
Sample Output
1
0
 
Author
teddy
 
Source
百万秦关终属楚
 
Recommend
teddy
 
/*
题意:二维坐标,然后三种操作,B x y 坐标(x,y)处的星星亮了,D x y坐标(x,y)处的星星灭了 Q X1 X2 Y1 Y2询问矩形内有多少颗
亮的星星 初步思路:二维树状数组,但是操作的时候先要查询一下当前位置星星的状态,还有就是查询的坐标可能不是x1<x2 y1<y2
*/
#include<bits/stdc++.h>
#define N 1010
#define lowbit(x) x&(-x)
using namespace std;
int t,X1,X2,Y1,Y2;
int n1,n2,m1,m2;
char op[];
int c[N][N];
void update(int x,int y,int val)
{
for(int i=x;i<N;i+=lowbit(i))
{
for(int j=y;j<N;j+=lowbit(j))
{
c[i][j]+=val;
}
}
// return val;//返回你实际搬运的东西
}
int getsum(int x,int y)
{
int s=;
for(int i=x;i>;i-=lowbit(i))
{
for(int j=y;j>;j-=lowbit(j))
{
s+=c[i][j];
}
}
return s;
}
void init(){
memset(c,,sizeof c);
}
int main(){
// freopen("in.txt","r",stdin);
init();
scanf("%d",&t);
while(t--){
scanf("%s",op);
if(op[]=='B'){
scanf("%d%d",&X1,&Y1);
X1++;
Y1++;
//先查询一下当前位置的星星是不是亮着的
if(getsum(X1,Y1)-getsum(X1-,Y1)-getsum(X1,Y1-)+getsum(X1-,Y1-)==){
// cout<<"有星星亮的"<<endl;
continue;
} update(X1,Y1,); }else if(op[]=='D'){
scanf("%d%d",&X1,&Y1);
X1++;
Y1++;
//先查询一下当前位置的星星是不是没亮
if(getsum(X1,Y1)-getsum(X1-,Y1)-getsum(X1,Y1-)+getsum(X1-,Y1-)==){
// cout<<"星星已经灭了"<<endl;
continue;
}
update(X1,Y1,-); }else{
scanf("%d%d%d%d",&X1,&X2,&Y1,&Y2);
X1++;X2++;
Y1++;Y2++;
// cout<<X1<<" "<<Y1<<" "<<X2<<" "<<Y2<<endl;
// cout<<getsum(X2,Y2)<<" "<<getsum(X1-1,Y2)<<" "<<getsum(X2,Y1-1)<<" "<<getsum(X1-1,Y1-1)<<endl;
n1=min(X1,X2),m1=min(Y1,Y2),n2=max(X1,X2),m2=max(Y1,Y2);
printf("%d\n",getsum(n2,m2)-getsum(n1-,m2)-getsum(n2,m1-)+getsum(n1-,m1-));
}
}
return ;
}

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

  1. hdu 2642 二维树状数组 单点更新区间查询 模板水题

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

  2. HDU_2642_二维树状数组

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others)Total Submi ...

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

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

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

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

  5. POJMatrix(二维树状数组)

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

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

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

  7. 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 ...

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

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

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

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

随机推荐

  1. Manacher详解

    之前的字符串题解中对Manacher的思想进行了简略的介绍,在这篇文章中,我将会详细的将这个算法的初衷和具体实现理论进行解释.声明一点,这是我个人的理解,可能有不全面之处,望多包涵.在之前的几篇文章中 ...

  2. ES6 Promise 对象

    Promise 的含义 Promise 是异步编程的一种解决方案,比传统的解决方案--回调函数和事件--更合理和更强大.它由社区最早提出和实现,ES6 将其写进了语言标准,统一了用法,原生提供了Pro ...

  3. 彻底弄懂AngularJS中的transclusion

    点击查看AngularJS系列目录 彻底弄懂AngularJS中的transclusion AngularJS中指令的重要性是不言而喻的,指令让我们可以创建自己的HTML标记,它将自定义元素变成了一个 ...

  4. Maven在Windows中的配置以及IDE中的项目创建

    Maven在Windows下的配置 1.Maven下载地址:http://maven.apache.org/download.cgi,下载红框里的版本即可. 2.解压到D盘: 3.修改配置文件sett ...

  5. “==”与"equals(object)"的区别

    一.对于基本数据类型而言只能用“==”,不能用equals来进行比较,若使用equals来进行比较,则不能通过编译 二.在非字符串的对象的比较中: “==”与“equals()”比较的均是对象在堆内存 ...

  6. 关于加载离线SHP文件、geodatabase文件所遇到的路径问题

    正文开始之前还是先吐槽一下,一行代码DEBUG了一天不知道怎么改,终于误打误撞弄出来了(以下以shp文件为例) 对于虚拟机测试 public String getPath(){ File sdDir ...

  7. C#进阶之AOP

    一.AOP概念(转自) AOP(Aspect-Oriented Programming,面向切面的编程),它是可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技 ...

  8. 如何维护一个1000 IP的免费代理池

    楔子 好友李博士要买房了, 前几天应邀帮他抓链家的数据分析下房价, 爬到一半遇到了验证码. 李博士的想法是每天把链家在售的二手房数据都抓一遍, 然后按照时间序列分析. 链家线上在交易的二手房数据大概有 ...

  9. RobotFramework自动化测试框架-移动手机自动化测试Click Element关键字的使用

    Click Element关键字用来模拟点击APP界面上的一个元素,该关键字接收一个参数[ locator ] ,这里的locator指的是界面元素的定位方式. 示例1:使用Click Element ...

  10. Ghost文件封装说明

    一.先列举目前Windows系统安装方式: 1.光盘安装 1.1 使用可刻录光驱将系统ISO文件刻录至DVD光盘,刻录工具比较多,QA目前使用Ultra ISO. 1.2 安装电脑从DVD光盘启动,无 ...