hdu 2642
这题应该就是标准的二维树状数组,应该没什么难度
处理一下x,y等于0的情况就过了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int maxn = 1e3+;
int c[maxn][maxn];
bool map[maxn][maxn];
void add(int x,int y,int d);
int getsum(int x,int y);
int main()
{
int t,x1,y1,x2,y2;
while(scanf("%d",&t) != EOF)
{
memset(c, , sizeof(c));
memset(map, false, sizeof(map));
while(t--)
{
string a;
cin >> a;
if(a == "B")
{
scanf("%d%d",&x1,&y1);
x1 ++; y1 ++;
if(map[x1][y1])
continue;
add(x1, y1, );
map[x1][y1] = true;
}
else if(a == "D")
{
scanf("%d%d",&x1,&y1);
x1 ++; y1 ++;
if(!map[x1][y1])
continue;
add(x1, y1, -);
map[x1][y1] = false;
}
else
{
scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
x1 ++; y1 ++; x2 ++; y2 ++;
if(x1>x2)swap(x1,x2);
if(y1>y2)swap(y1,y2);
int k = getsum(x2, y2) + getsum(x1-, y1-) - getsum(x1-,y2) - getsum(x2, y1-);
printf("%d\n",k);
}
}
} }
int lowbit(int k)
{
return k&(-k);
}
void add(int x,int y,int d)
{
int i,j;
for(i=x;i<maxn;i+=lowbit(i))
{
for(j=y;j<maxn;j+=lowbit(j))
{
c[i][j] += d;
}
}
}
int getsum(int x,int y)
{
int i,j;
int sum = ;
for(i=x;i>;i-=lowbit(i))
for(j=y;j>;j-=lowbit(j))
sum += c[i][j];
return sum;
}
hdu 2642的更多相关文章
- hdu 2642 Stars
Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky. To make t ...
- hdu 2642 二维树状数组 单点更新区间查询 模板水题
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...
- hdu 2642 Stars 【二维树状数组】
题目 题目大意:Yifenfei是一个浪漫的人,他喜欢数天上的星星.为了使问题变得更容易,我们假设天空是一个二维平面,上面的星星有时会亮,有时会发暗.最开始,没有明亮的星星在天空中,然后将给出一些信息 ...
- hdu 2642二维树状数组 单点更新区间查询 模板题
二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...
- hdu2642二维树状数组,单点修改+区间查询
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/2642/ 代码如下: #include<bits/stdc++.h> using namespace ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- ES6 Reflect的认识
首先我们要了解一下,为什么会新添加这么一个全局对象?如果你看过Reflect的一些函数,你就会发现,这个对象上的方法基本上都可以从Object上面找到,找不到的那些,也是可以通过对对象命令式的操作去实 ...
- Numpy array分割
1.纵向分割 >>> import numpy as np >>> A = np.arange(12).reshape((3, 4)) >>> p ...
- Numpy array 合并
1.np.vstack() :垂直合并 >>> import numpy as np >>> A = np.array([1,1,1]) >>> ...
- JavaScript.how-to-debug-javascript
How to debug JavaScript code 1. 写一个HTML文件.例如: <!DOCTYPE html> <html> <title>Web Pa ...
- lazarus的动态方法和虚拟方法
动态方法和虚拟方法在delphi里面分别表示: 动态方法 当需要调用父类.祖先类的被覆盖方法的时候,是查找继承树,当找到,就调用.减少了VMT占用,但调用慢一些. 虚拟方法 和动态方法不同的是,记录了 ...
- debian9安装mysql mariadb
debian9下mysql 替换成mariadb-server-10.1 不过两者类似 具体可见 <MySQL和mariadb区别> http://ask.chinaunix.net/qu ...
- 各种编译不通过xcode
2017-08-24 Apple Mach-O Linker (Id) Error Linker command failed with exit code 1 (use -v to see invo ...
- 1.preparation
1)Evarobot 安装 http://wiki.ros.org/Robots/evarobot/Tutorials/indigo/Evarobot%20Installation 2)PC 安装 a ...
- IOS初级:NSKeyedArchiver
NSKeyedArchiver对象归档 首先要实现<NScoding>里面的两个代理方法initWithCoder,encodeWithCoder @property (nonatomic ...
- Tomcat新问题 还没有解决:the apr based apache tomcat native librariy which allows optional perf...........
问题信息详细: 2012-5-18 18:41:54 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apa ...