Stars(二维树状数组)
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 |
|
Sample Output
1 |
|
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(二维树状数组)的更多相关文章
- hdu 2642 二维树状数组 单点更新区间查询 模板水题
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...
- HDU_2642_二维树状数组
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)Total Submi ...
- 二维树状数组 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 ...
随机推荐
- 逆向实战干货,快速定位自动捡阳光Call,或者标志
逆向实战干货,快速定位自动捡阳光Call,或者标志 注意: 关于CE和OD的使用,这里不再多说,快速定位,默认大家已经有了CE基础,或者OD基础. 第一种方法,找Call 第一步,打开CE,搜索阳光值 ...
- 11 Linear Models for Classification
一.二元分类的线性模型 线性分类.线性回归.逻辑回归 可视化这三个线性模型的代价函数 SQR.SCE的值都是大于等于0/1的 理论分析上界 将回归应用于分类 线性回归后的参数值常用于pla/pa/lo ...
- js特效遮罩层(弹出层)
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- Count(*), Count(1) 和Count(字段)的区别
1. count(1) and count(*) 当表的数据量大些时,对表作分析之后,使用count(1)还要比使用count(*)用时多了! 从执行计划来看,count(1)和count(*)的 ...
- Java并发(一、概述)
离上次写博客又隔了很久,心中有愧.在我不断使用Java的过程中,几乎都是拿来就用,就Java并发这块我还没有系统的梳理过,趁着国庆有空余时间,把它梳理一遍.以下部分内容参考相关书籍,以作学习之用,特此 ...
- 一文为你详细讲解对象映射库【AutoMapper】所支持场景
前言 在AutoMapper未出世前,对象与对象之间的映射,我们只能通过手动为每个属性一一赋值,时间长了不仅是我们而且老外也觉得映射代码很无聊啊.这个时候老外的所写的强大映射库AutoMapper横空 ...
- 单独创建一个Android Test Project 时junit 的配置和使用
现在的集成ADT后Eclipse都可以直接创建Android Test Project 如图所示: 命名后选择你要测试的单元程序,比如我自己准备测试sms,便可以如图所示那样选择 本人新建的测试工程为 ...
- python中html解析-Beautiful Soup
1. Beautiful Soup的简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: Beautiful Soup提供一些简单的.pyt ...
- C#中 什么是装箱和拆箱
装箱:将值类型包装为引用类型 拆箱:将引用类型转换为值类型 例如 objetct obj = null; obj = ; //装箱 int i = (int) obj; //拆箱
- struts2-学习笔记(三)
Struts2 学习笔记(三) 1.ognl概述: OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目. Struts2框架使用O ...