4C. Stars

Time Limit: 2000ms
Case Time Limit: 2000ms
Memory Limit: 65536KB
 
64-bit integer IO format: %I64d      Java class name: Main
 
 
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 解题思路:二维树状数组模板题,注意范围,通常二维数状数组de范围是从1开始的,而题目要求从0开始,所以要偏移1.还有因为星星只有两种状态,为了避免连续对同一个星星进行同样的操作导致结果出错,需要一个数组进行标记状态!
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
const int maxn = ;
int tree[maxn][maxn];
bool br[maxn][maxn];
int lowbit(int x) {
return x&(-x);
}
void update(int x,int y,int val) {
int t;
while(x < maxn) {
t = y;
while(t < maxn) {
tree[x][t] += val;
t += lowbit(t);
}
x += lowbit(x);
}
}
int sum(int x,int y) {
int temp = ,t;
while(x) {
t = y;
while(t) {
temp += tree[x][t];
t -= lowbit(t);
}
x -= lowbit(x);
}
return temp;
}
int main() {
int m,i,j,a,b,c,d;
char s[];
scanf("%d",&m);
while(m--) {
scanf("%s",s);
if(s[] == 'B') {
scanf("%d %d",&a,&b);
if(!br[a+][b+]) {
br[a+][b+] = true;
update(a+,b+,);
}
} else if(s[] == 'D') {
scanf("%d %d",&a,&b);
if(br[a+][b+]) {
update(a+,b+,-);
br[a+][b+] = false;
}
} else if(s[] == 'Q') {
scanf("%d %d %d %d",&a,&b,&c,&d);
if(a > b) swap(a,b);
if(c > d) swap(c,d);
b++;d++;
printf("%d\n",sum(b,d)+sum(a,c)-sum(a,d)-sum(b,c));
}
}
return ;
}

4C. Stars的更多相关文章

  1. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  2. C-RAN 集中化、协作化、云化、绿色节能(4C)

    中国移动C-RAN力拼第4个C:2018年6月外场组网验证 http://www.c114.net ( 2016/11/22 07:41 ) C114讯 11月22日早间消息(子月)2009年,中国移 ...

  3. MAGIC XPA最新版本Magic xpa 2.4c Release Notes

    New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...

  4. POJ 2352 Stars(树状数组)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 Descripti ...

  5. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  6. Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...

  7. XidianOJ 1177 Counting Stars

    题目描述 "But baby, I've been, I've been praying hard,     Said, no more counting dollars     We'll ...

  8. POJ-2352 Stars 树状数组

    Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...

  9. hdu 1541/poj 2352:Stars(树状数组,经典题)

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

随机推荐

  1. jq或zp监听input的value改变问题

    $(document).on('input propertychange','#citySelectorValue',function () { alert("s"); } 以上J ...

  2. jsp九大内置对象响应类型

     内置对象            类型request            httpServletRequestout                jspWriterresponse         ...

  3. react-native入门学习( 一 )

    开发环境配置 因为个人电脑是windows7环境,所以在选择安装react-native 环境的时候是用的 windows+androidreact-native中文网文档地址  https://re ...

  4. AJPFX分享JAVA修饰符详解

    1.类的修饰符分为:可访问控制符和非访问控制符两种. 可访问控制符是:公共类修饰符 public 非访问控制符有:抽象类修饰符 abstract :最终类修饰符 final 1 )公共类修饰符 pub ...

  5. option标签selected="selected"属性失效的问题

    要在select标签上面加上autocomplete="off"关闭自动完成,不然浏览器每次刷新后将自动选择上一次关闭时的option,这样默认属性selected="s ...

  6. Android实现按钮点击效果(第一次点击变色,第二次恢复)

    1.首先创建一个按钮 <Button android:id="@+id/click" android:layout_width="fill_parent" ...

  7. MySQL主从复制原理介绍

    1)在mysql主库上,将改变记录到二进制日志(binary log)中. 2)在mysql从库上,IO线程将mysql主库上二进制日志(binary log)复制到中继日志(replay log)中 ...

  8. tomcat配置 —— 各个目录的作用

    tomcat各目录(文件)作用 tomcat-7.0.50解压版,主目录一览: 我们可以看到主目录下有bin,conf,lib,logs,temp,webapps,work 7个文件夹,下面对他们分别 ...

  9. 11gR2新特性---Gpnp守护进程

    在这篇文章中,我们会对11gR2 新的守护进程(资源名称ora.gpnpd)进行介绍,其中包含的gpnp的功能,启动顺序和基本的诊断方法. gpnp全称为grid plug and play,该组件的 ...

  10. Scala 的list

    9.1 使用列表 列表类型:跟数组一样,列表也是同质化的(homogeneous).即所有元素都要是同种类型. 列表结构:所有列表由两部分组成:Nil 和 ::(cons). 基本操作:主要有三个:h ...