题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1892

题目大意:

题目大意:有很多方格,每个方格对应的坐标为(I,J),刚开始时每个格子里有1本书,然后让你统计一片区域有多少本书,还可以增加书和减少,移动书。

解题思路:

直接二维数组数组模拟

注意:

每个下标+1,从(1, 1)开始

求区域和的时候给出的x1 y1 和x2 y2不是标准的正对角线,需要转化

  #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<deque>
#include<sstream>
#include<cctype>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, s, t) for(int i = (s); i < (t); i++)
#define MEM(a, x) memset(a, x, sizeof(a));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const double eps = 1e-;
const int INF = << ;
const int dir[][] = {,,,,,-,-,};
const double pi = 3.1415926535898;
int T, n, m, cases;
int tree[maxn][maxn], a[maxn][maxn];
int lowbit(int x)
{
return x&(-x);
}
int sum(int x, int y)
{
int ans = ;
for(int i = x; i > ; i -= lowbit(i))
for(int j = y; j > ; j -= lowbit(j))
ans += tree[i][j];
return ans;
}
void add(int x, int y, int d)
{
for(int i = x; i < maxn; i += lowbit(i))
{
for(int j = y; j < maxn; j += lowbit(j))
{
tree[i][j] += d;
}
}
}
int main()
{
scanf("%d", &T);
char s[];
int x, y, x1, y1, x2, y2, d;
while(T--)
{
scanf("%d", &n);
MEM(tree, );
for(int i = ; i < maxn; i++)
{
for(int j = ; j < maxn; j++)
{
add(i, j, );
a[i][j] = ;
}
}
printf("Case %d:\n", ++cases);
while(n--)
{
scanf("%s", s);
if(s[] == 'S')
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
///不是标准的x1<x2, y1<y2,要对其进行转化
int a, b, c, d;
a = min(x1, x2);a++;
b = min(y1, y2);b++;
c = max(x1, x2);c++;
d = max(y1, y2);d++;
printf("%d\n", sum(c, d) + sum(a - , b - ) - sum(a - , d) - sum(c, b - ));
}
else if(s[] == 'A')
{
scanf("%d%d%d", &x, &y, &d);
x++, y++;
add(x, y, d);
a[x][y] += d;
}
else if(s[] == 'D')
{
scanf("%d%d%d", &x, &y, &d);
x++, y++;
if(d > a[x][y])d = a[x][y];
add(x, y, -d);
a[x][y] -= d;
}
else
{
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &d);
x1++, y1++, x2++, y2++;
if(d > a[x1][y1])d = a[x1][y1];
add(x1, y1, -d);
add(x2, y2, d);
a[x1][y1] -= d;
a[x2][y2] += d;
}
}
}
return ;
}

hdu-1892 See you~---二维树状数组运用的更多相关文章

  1. HDU 1892(书架统计 二维树状数组)

    题意是在二维平面上在一些位置上进行数据的增删改查操作,使用树状数组(了解树状数组点这里) 原来的树状数组在求区间和时是 sum( x, y ) = getsum( y ) - getsum( x - ...

  2. HDU 1892 See you~ (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1892 See you~ Problem Description Now I am leaving h ...

  3. 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)

    BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...

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

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

  5. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. HDU 5517---Triple(二维树状数组)

    题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...

  7. HDU 5517 【二维树状数组///三维偏序问题】

    题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...

  8. HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle  Accepts: 42  Submissions: 26 ...

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

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

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

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

随机推荐

  1. 工具类_GsonUtils

    import java.lang.reflect.Type; import com.google.gson.Gson; /** * Gson工具类 2015-02-01<br/> * 1, ...

  2. restTemplate使用

    转载博主: https://blog.csdn.net/itguangit/article/details/78825505 https://www.cnblogs.com/zhaoyan001/p/ ...

  3. 问题:git处理中文名称时候显示为编码形式(已解决)

    问题描述: Untracked files: (use "git add <file>..." to include in what will be committed ...

  4. Vuejs 实现权限管理

    程序运行时,router只配置登陆 首页404 等基本页面 import Main from '@/views/Main.vue'; // 不作为Main组件的子页面展示的页面单独写,如下 expor ...

  5. The 'gridview' module MUST be setup in your Yii configuration file.

    解决方法:common的config的main.php中添加 'gridview' => ['class' => 'kartik\grid\Module'], 在vender的compos ...

  6. 《mac的git安装手册-1》

    <mac的git安装手册-1> 下载地址 https://git-scm.com/downloads 如果遇到上面这个问题打开系统偏好设置: OK,这样就能安装了

  7. oracle 12.1.0.2的mgmt 导致的ORA-01017 bug

    两节点12c RAC,在两节点上export ORACLE_SID再sqlplus / as sysdba都正常登录,然而Commvault通过service_name方式(sqlplus sys/p ...

  8. vector 中需要注意的东西!

    vector的erase方法注意点!!! C++11是这样的: iterator erase (const_iterator position); iterator erase (const_iter ...

  9. 2019.03.20 读书笔记 关于Reflect与Emit的datatable转list的效率对比

    Reflect public static List<T> ToListByReflect<T>(this DataTable dt) where T : new() { Li ...

  10. python 下载图片

    import requests from PIL import Image from io import BytesIO url = 'http://image2.buslive.cn/shp/upl ...