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. [转]Formatting the detail section to display multiple columns (水晶报表 rpt 一页多列)

    本文转自:http://www.bofocus.com/formatting-the-detail-section-to-display-multiple-columns/ Format the de ...

  2. TCP简单程序

    服务器段: package com.dcz.socket; import java.io.IOException; import java.io.OutputStream; import java.n ...

  3. Windows下Apache+PHP+MySQL开发环境的搭建(WAMP)

    准备工作: 1.下载apache服务器安装包,官网http://www.apache.org/,下载地址:http://httpd.apache.org/download.cgi 2.下载MySQL, ...

  4. this详解,对执行上下文说 Yes

    this 指向多变,很多隐蔽的 bug 都缘于它.与此同时,this 强大灵活,如果能熟练驾驭,就会写出更简洁.优雅的代码. 社区上对于 this 的讲解虽然不少,但缺乏统一梳理. this 相关知识 ...

  5. Android:Service通知Activity更新界面

    Android有四大组件,其中包括service和activity,那么在使用的过程中,我们最常遇到的问题是他们之间的通信问题. 1.首先Activity调用Service 这个是比较基础的,它有两种 ...

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

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

  7. hihoCoder #1079 : 离散化 (线段树,数据离散化)

    题意:有一块宣传栏,高一定,给出长度,再给出多张海报的张贴位置,问还能见到几张海报(哪怕有一点被看到)?假设海报的高于宣传栏同高. 思路:问题转成“给出x轴上长为L的一条线段,再用n条线段进行覆盖上去 ...

  8. Integer比较浅析

    //Integer 型比较假如是使用 == ,只能比较数值为-128~127数值; 在这个范围内使用的是自动装箱拆箱: //.intValue()使用这个需要确认属性不为null; //equals( ...

  9. layui 数据table隐藏表头

    $('.layui-table .layui-table-cell > span').css({'font-weight': 'bold'});//表头字体样式 /*$('th').css({' ...

  10. bootstrap 按钮组的嵌套

    您可以在一个按钮组内嵌套另一个按钮组,即,在一个 .btn-group 内嵌套另一个 .btn-group .当您想让下拉菜单与一系列按钮组合使用时,就会用到这个. 实例: <!DOCTYPE ...