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. go实现生产者消费者

    package main import ( "fmt" "math/rand" ) func main() { ch := make(chan int) don ...

  2. JDk安装及环境变量的配置

    一.JDK的安装 1.打开下载好的安装包(我在这里附上一个百度云连接,https://pan.baidu.com/s/1o3nx0kbmecAISeneGqykLQ    提取码:jnw6) 傻瓜式安 ...

  3. Java编程基础-数组

    一.数组的定义. 1.数组的含义:数组是一组具有相同数据类型的元素的有序集合.数组可以分为一维数组和多维数组.(数组是一个引用类型的容器,从0开始编号存储相同数据类型的数据.) 2.数组的定义语法格式 ...

  4. 洛谷 P1474 货币系统 Money Systems

    P1474 货币系统 Money Systems !! 不是noip2018的那道题. 简单的多重背包的变式. #include <iostream> #include <cstdi ...

  5. uvm_reg_defines——寄存器模型(四)

    文件: src/marcos/uvm_reg_defines 类: 无 该文件是寄存器模型src/reg/* 文件对于的宏文件,主要定义了寄存器地址位宽,寄存器数据位宽,字节的大小.计算机从最初的8, ...

  6. uvm_agent——007(特工)

    詹姆斯·邦德作为007的代言人,很好地诠释了agent的含义.但是在计算机系统中agent(代理)指能自主活动的软件或者硬件实体.在UVC中agent作为容器,实例化VIP的所有模块包括driver, ...

  7. java.lang.IllegalArgumentException: name MUST NOT NULL! at org.nutz.dao.impl.NutDao.fetch

    Nutz传值报错问题 作者:Vashon 时间:20150902 平台:Nutz框架 Java后台方法中拿值时报的错 报错信息: java.lang.IllegalArgumentException: ...

  8. MySQL备份还原介绍

    window系统下 1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u dbuser -p dbname > dbname.sql ...

  9. 使用JOSM编辑OpenStreetMap地图

    申明:转载请注明出处! 网上关于JOSM的使用大多只介绍了如何安装和优缺点,对于我这种小白完全还是不会,于是Google了一番,国外关于JOSM的使用的文章还是很多的, 选中一篇讲解的非常详细来翻译, ...

  10. codevs 3344 迷宫

    时间限制: 1 s  空间限制: 32000 KB  题目等级 : 黄金 Gold 题目描述 Description 小刚在迷宫内,他需要从A点出发,按顺序经过B,C,D……,到达最后一个点,再回到A ...