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

处理一下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. C++中 左值和右值的区别

    总结: C++11中所有的值属于左值,右值两者之一. 左值引用:指的是可以放在赋值表达式左边的事物——在堆上或者栈上分配的命名对象或者其他对象成员——有明确的内存地址. 对左值的const引用创建临时 ...

  2. 前端面试问题js汇总

    1.javascript的typeof返回哪些数据类型 Object number function boolean underfind 2,数组方法pop() push() unshift()shi ...

  3. JVM 体系结构概述 (一)

    一.jvm运行在操作系统之上的,它与硬件没有直接交互: 二.JVM体系结构概览 JVM的基本结构:类加载器.执行引擎.运行时数据区.本地方法接口: 过程:class文件 ----> 类加载器 - ...

  4. BZOJ 3123 [SDOI2013] 森林 - 启发式合并 主席树

    Description 给你一片森林, 支持两个操作: 查询$x$到$y$的$K$大值,  连接两棵树中的两个点 Solution 对每个节点$x$动态开权值线段树, 表示从$x$到根节点路径上权值出 ...

  5. BZOJ1855 股票交易 单调队列优化 DP

    描述 某位蒟佬要买股票, 他神奇地能够预测接下来 T 天的 每天的股票购买价格 ap, 股票出售价格 bp, 以及某日购买股票的上限 as,  某日出售股票上限 bs, 并且每次股票交 ♂ 易 ( 购 ...

  6. ubuntu下firefox打开mht文件

    1.安装firefox插件:UnMHT 插件地址:http://www.unmht.org/unmht/en_index.html 2.用firefox打开mht文件

  7. synchronized Lock

    synchronized和Lock都是Java语言提供的两种实现对共享资源进行同步的机制.其中synchronized使用Object对象本身的wait().notify().notifyAll()方 ...

  8. Ionic学习

    1. 原来Http不能直接加在普通类里,下面的报错 import { Component } from '@angular/core'; import { NavController } from ' ...

  9. Nodejs+Mongo+WebAPI

    Nodejs+Mongo+WebAPI集成 1.[ 目录]: |- models/bear.js |- node_modules/ |- express |- mongoose |- body-par ...

  10. wireshark源码分析二

    一.源代码结构 在wireshark源代码根目录下,可以看到以下子目录: 1)物理结构     其中,epan文件夹负责所有网络协议识别工作,plugins里面存放了wireshark所有插件,gtk ...