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. 面向对象编程笔记--static

    通过static方法,提供静态的不需要实例化即可访问的方法或属性.所有的调用者可以使用同一个类(不实例化)或对象(只实例化一次),可以应用的场景: 1)各个调用者共享数据,协同工作. 2)对象只可以实 ...

  2. VirtualBox 磁盘容量调整

    起因 此前用VBox,初始时动态或固定分配的磁盘容量用完了就再重新建一个磁盘,但是有个虚拟机的系统分区容量不够了,把整个磁盘都分成系统盘仍然不够,于是研究了下磁盘容量调整问题. 正文 1,从当前虚拟机 ...

  3. sqlserver 使用脚本创建Sql Server代理作业

    use master GO /* --开启sql server代理 sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_con ...

  4. Sql Server合并多行询数据到一行:使用自连接、FOR XML PATH('')、STUFF或REPLACE函数

    示例表 tb 数据如下 id value ----- 1 aa 1 bb 2 aaa 2 bbb 2 ccc SELECT id, [val] = ( SELECT [value] + ',' FRO ...

  5. 从源码看 angular/material2 中 dialog模块 的实现

    本文将探讨material2中popup弹窗即其Dialog模块的实现. 使用方法 引入弹窗模块 自己准备作为模板的弹窗内容组件 在需要使用的组件内注入 MatDialog 服务 调用 open 方法 ...

  6. 深度学习入门篇--手把手教你用 TensorFlow 训练模型

    欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:付越 导语 Tensorflow在更新1.0版本之后多了很多新功能,其中放出了很多用tf框架写的深度网络结构(https://git ...

  7. Android之View绘制流程源码分析

    版权声明:本文出自汪磊的博客,转载请务必注明出处. 对于稍有自定义View经验的安卓开发者来说,onMeasure,onLayout,onDraw这三个方法都不会陌生,起码多少都有所接触吧. 在安卓中 ...

  8. chromium源码阅读--Browser进程初始化

    最近在研读chromium源码,经过一段懵懂期,查阅了官网和网上的技术文章,是时候自己总结一下了,首先IPC message loop开始吧,这是每个主线程必须有的一个IPC消息轮训主体,类似之前的q ...

  9. Bootstrap 禁用滚动条

    Bootstrap中禁用滚动条的方法 逻辑: 当点击弹窗按钮后,js会为body元素添加一个modal-open的类,该类主要内容如下 .modal-open .modal { overflow-x: ...

  10. C++大数精度计算(带小数点)

    转: (原出处不可考,若有侵权,请联系我立即删除) 头文件: // WTNumber.h: interface for the CWTNumber class. // //////////////// ...