hdu 2642 Stars 【二维树状数组】
题目大意:Yifenfei是一个浪漫的人,他喜欢数天上的星星。为了使问题变得更容易,我们假设天空是一个二维平面,上面的星星有时会亮,有时会发暗。最开始,没有明亮的星星在天空中,然后将给出一些信息,“B XY”,其中“B”代表明亮,x代表X坐标和Y代表Y坐标是指在(X,Y)的明星是光明的,而在“D XY”'D'的意思是灰暗的星星在(X , Y).当得到“Q X1 X2 Y1 Y2”的查询,你应该告诉Yifenfei在该地区有多少明亮的星星在X1,X2,Y1,Y2决定的矩形里。
B x y:点(x,y)处的星星变亮
D x y:点(x,y)处的星星变暗
Q x1 x2 y1 y2:查询左下角(x1,y1)和右上角(x2,y2)的矩形
#include <iostream>
#include <cstdio>
using namespace std;
const int Max = 1010;
int c[Max][Max];
int vis[Max][Max];
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int val)
{
int t;
while(x<=Max){
t = y;
while(t<=Max){
c[x][t]+=val;
t+=lowbit(t);
}
x+=lowbit(x);
}
}
int sum(int x,int y)
{
int res=0;
while(x>0){
int t = y;
while(t>0){
res+=c[x][t];
t-=lowbit(t);
}
x-=lowbit(x);
}
return res;
}
int main()
{
int M,x,y;
string str;
scanf("%d",&M);
while(M--)
{
cin>>str;
if(str[0]=='B'){
scanf("%d%d",&x,&y);
x++,y++;
if(!vis[x][y]){
vis[x][y] = 1;
update(x,y,1);
}
}else if(str[0]=='Q'){
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
x1++,x2++,y1++,y2++;
int X,Y;
X = max(x1,x2);
x = min(x1,x2);
Y = max(y1,y2);
y = min(y1,y2);
int ans = sum(X,Y)+sum(x-1,y-1)-sum(X,y-1)-sum(x-1,Y);
printf("%d\n",ans);
}else{//D
scanf("%d%d",&x,&y);
x++,y++;
if(vis[x][y]){
vis[x][y]=0;
update(x,y,-1);
}
}
}
return 0;
}
hdu 2642 Stars 【二维树状数组】的更多相关文章
- hdu 5517 Triple(二维树状数组)
Triple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 5517---Triple(二维树状数组)
题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...
- HDU 5517 【二维树状数组///三维偏序问题】
题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...
- HDU 4456(二维树状数组+坐标转换)
题目链接:Problem - 4456 看别人叙述看的心烦,于是我自己画了一张图. 上图. 上代码 #include <iostream> #include <cstdio> ...
- hdu 2642 二维树状数组 单点更新区间查询 模板水题
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...
- hdu 2642二维树状数组 单点更新区间查询 模板题
二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...
- Stars(二维树状数组)
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Submiss ...
- 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)
BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- HDU1559 最大子矩阵 (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) ...
随机推荐
- js 箭头函数
箭头函数 ES6标准新增了一种新的函数:Arrow Function(箭头函数). x => x * x相当于: function (x) { return x * x; }箭头函数相当于匿名函 ...
- MySql数据库 sql查询增加序号的伪列
在查询数据库的时候,我们有时候需要对查询出来的数据加上序列,1,2,3,……n 例如:我们根据表的某个字段排序后,要对这些数据加上序列,这个时候序号常常不是我们建表时设置好的自增的主键id,怎么办呢? ...
- guide dpdk
Welcome to DPDK Guide! Contents: Setting up DPDK Important Prerequisites Setting up repositories Red ...
- 第一次java实验报告
实验一Java开发环境的熟悉-1 步骤: mkdir +20165213exp1创建20165213exp1这个目录 cd +20165213zqh进入这个目录 mkdir+src+bin创建目录sr ...
- python的杨辉三角
# # / \ # # / \ / \ # # / \ / \ / \ # # / \ / \ / \ / \ # # / \ / \ / \ / \ / \ # # ---------------- ...
- Python module : simuPOP
conda config --add channels conda-forge conda install simupop simuPOP is a general-purpose individua ...
- 关于Code Review
为了保证代码质量,我们团队内部一直在推行Code Review.现在Code Review帮我们发现了很多代码的问题,提升了代码的可读性和质量,同时我们在Code Review上也花费了很多时间,有些 ...
- logcat命令详解【二】
eclipse 自带的 LogCat 工具太垃圾了, 开始用 adb logcat 在终端查看日志; 1. 解析 adb logcat 的帮助信息 在命令行中输入 adb logcat --help ...
- IntelliJ IDEA 2017版 spring-boot2.0.4的yml配置使用
一.必须配置字端两个 server: port: 8080 servlet: context-path: /demo 二.两种mvc转换springboot,一种是注解,一种就是.yml或proper ...
- vue中的路由嵌套
1定义组件 const Index = { template:` <div>首页</div> ` } const Order = { template:` <div> ...