这题应该就是标准的二维树状数组,应该没什么难度

处理一下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的更多相关文章

  1. hdu 2642 Stars

    Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky. To make t ...

  2. hdu 2642 二维树状数组 单点更新区间查询 模板水题

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

  3. hdu 2642 Stars 【二维树状数组】

    题目 题目大意:Yifenfei是一个浪漫的人,他喜欢数天上的星星.为了使问题变得更容易,我们假设天空是一个二维平面,上面的星星有时会亮,有时会发暗.最开始,没有明亮的星星在天空中,然后将给出一些信息 ...

  4. hdu 2642二维树状数组 单点更新区间查询 模板题

    二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...

  5. hdu2642二维树状数组,单点修改+区间查询

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/2642/ 代码如下: #include<bits/stdc++.h> using namespace ...

  6. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. 阿里巴巴Java开发手册及Java代码规约扫描eclipse插件

    一.github地址: https://github.com/alibaba/p3c 二..eclipse插件的安装 此处示例采用eclipse,版本为 Neon.1 Release RC3 (4.6 ...

  2. andorid 网格视图GridView

    .xml <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android=&qu ...

  3. git回退文件修改

    假设git仓库某个文件的提交信息如下: [cxy@localhost-live mate-power-manager]$ git log -n3 SPECS/mate-power-manager.sp ...

  4. 在iOS 8及以后使用UIAlertController 等各种弹出警告通知

    原文转自:在iOS 8中使用UIAlertController 感谢作者分享,自我学习之用 iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UI ...

  5. PS制作纸质复古野外露营插画分享

    经常有人说一些复古风,就觉得蛮难,其实制作过程其实没有想象中复杂,从1850年到2017年,通过这160多年里的平面设计,给我们的作品添加上一些新鲜的灵感和活力,本次教程就来教大家用PS做出耐看的纸质 ...

  6. hook api实现

    https://www.cnblogs.com/findumars/p/8734116.html https://blog.csdn.net/lonelyrains/article/details/2 ...

  7. Ubuntu 配置双网卡的问题

    一台双网卡电脑拥有两个网关是不可能的,因为默认网关(default gateway)只能是一个.给Ubuntu Linux服务器安装两块网卡,分别设置不同的ip和网关(内网和外网),外网的通过外网网卡 ...

  8. Python之路(第十四篇)os模块

    一.os模块 1.os.getcwd() 获取当前工作目录(当前工作目录默认都是当前文件所在的文件夹) import os print(os.getcwd()) 2.os.chdir(path) 改变 ...

  9. SCM_SVN_CVS

    SCM_SVN_CVS SCM:一种用于记录并控制软件数据的工具.比如有:CVS(有过时趋势)和SVN(更加常用). 版本控制的概念: Respository:仓库 Workspace:工作台 Del ...

  10. android 打开新窗口

    ImageView loginBtn = (ImageView)findViewById(R.id.login_button); loginBtn.setOnClickListener(new Vie ...