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 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- istio prometheus预警Prometheus AlertManager
1.安装alertmanager kubectl create -f 以下文件 alertmanager-templates.yaml.configmap.yaml.deployment.yaml.s ...
- 三种简单排序算法(java实现)
一.冒泡排序 算法思想:遍历待排序的数组,每次遍历比较相邻的两个元素,如果他们的排列顺序错误就交换他们的位置,经过一趟排序后,最大的元素会浮置数组的末端.重复操 作 ...
- Android.HowToDefineCustomView
Custom View Errors E1 在使用自定义CustomView时,出现以下runtime error: Android.View.InflateException: Binary XML ...
- ORM学员管理系统单表查询示例
前期准备工作 首先创建好一个项目 一:必须使用MySQL创建一个库 因为ORM只能对表和数据进行处理,所以库必须自己创建 create database mysite; 二:进行相关的配置 在项目my ...
- BZOJ1178或洛谷3626 [APIO2009]会议中心
BZOJ原题链接 洛谷原题链接 第一个问题是经典的最多不相交区间问题,用贪心即可解决. 主要问题是第二个,求最小字典序的方案. 我们可以尝试从\(1\to n\)扫一遍所有区间,按顺序对每一个不会使答 ...
- python入门科普IDE工具和编译环境
应友人之邀,今天来讲述python的一些入门内容.本次讲解的并不是语法或者某个模块. python下载安装 大多数 Linux 发行版在默认安装的情况 ...
- mui-手动触发下拉刷新
mui-手动触发下拉刷新 下拉刷新结束 mui官方文档中下拉刷新结束方法,不生效, 文档地址 1 mui('#refreshContainer').pullRefresh().endPulldow ...
- render函数的简单使用
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python3.4对已经存在的excel写入数据
#!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...
- idea设置字体大小
第一次玩儿idea,也是个新手小白,甚是惭愧,也是一步步慢慢摸索,下面我们按照步骤一步步操作 就可以了. 1.首先,先设置代码的字体大小: 2.设置周围菜单栏的字体大小: 3.设置控制台的字体大小: