思路:就是一个很普通的二维树状数组,注意的是x1,y1不一定在x2,y2的左下方

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define Maxn 1105
#define lowbit(x) (x&(-x))
using namespace std;
int C[Maxn][Maxn],n=,LIST[Maxn][Maxn];
int Sum(int i,int j)
{
int sum=;
int y;
y=j;
while(i)
{
j=y;
while(j)
{
sum+=C[i][j];
j-=lowbit(j);
}
i-=lowbit(i);
}
return sum;
}
void update(int i,int j,int val)
{
int y,z;
y=j;
while(i<=n)
{
j=y;
while(j<=n)
{
C[i][j]+=val;
j+=lowbit(j);
}
i+=lowbit(i);
}
}
int main()
{
int x1,x2,y1,y2,q,t,num,i,Case=,j;
char str[];
for(i=;i<=;i++)
for(j=;j<=;j++)
update(i,j,);
for(i=;i<=;i++)
for(j=;j<=;j++)
LIST[i][j]=C[i][j];
scanf("%d",&t);
Case=;
while(t--)
{
memcpy(C,LIST,sizeof(C));
scanf("%d",&q);
printf("Case %d:\n",++Case);
for(i=;i<=q;i++)
{
scanf("%s",&str);
if(str[]=='S')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1++,y1++,x2++,y2++;
int a1,b1,a2,b2;
a1=min(x1,x2);a2=max(x1,x2);b1=min(y1,y2);b2=max(y1,y2);
printf("%d\n",Sum(a2,b2)-Sum(a1-,b2)-Sum(a2,b1-)+Sum(a1-,b1-));
}
if(str[]=='A')
{
scanf("%d%d%d",&x1,&y1,&num);
x1++,y1++;
update(x1,y1,num);
//printf("%d**\n",Sum(x1,y1));
}
if(str[]=='D')
{
int temp;
scanf("%d%d%d",&x1,&y1,&num);
x1++,y1++;
temp=Sum(x1,y1)-Sum(x1-,y1)-Sum(x1,y1-)+Sum(x1-,y1-);
if(temp>=num)
update(x1,y1,-num);
else
update(x1,y1,-temp);
}
if(str[]=='M')
{
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&num);
x1++,y1++,x2++,y2++;
int temp=Sum(x1,y1)-Sum(x1-,y1)-Sum(x1,y1-)+Sum(x1-,y1-);
if(temp>=num)
{
update(x1,y1,-num);
update(x2,y2,num);
}
else
{
update(x1,y1,-temp);
update(x2,y2,temp);
}
}
}
}
return ;
}

hdu 1892 树状数组的更多相关文章

  1. hdu 4638 树状数组 区间内连续区间的个数(尽可能长)

    Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  2. hdu 4777 树状数组+合数分解

    Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. HDU 2852 (树状数组+无序第K小)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2852 题目大意:操作①:往盒子里放一个数.操作②:从盒子里扔掉一个数.操作③:查询盒子里大于a的第K小 ...

  4. HDU 4911 (树状数组+逆序数)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4911 题目大意:最多可以交换K次,就最小逆序对数 解题思路: 逆序数定理,当逆序对数大于0时,若ak ...

  5. hdu 5792(树状数组,容斥) World is Exploding

    hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i ...

  6. HDU 1934 树状数组 也可以用线段树

    http://acm.hdu.edu.cn/showproblem.php?pid=1394 或者是我自己挂的专题http://acm.hust.edu.cn/vjudge/contest/view. ...

  7. 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...

  8. 【模板】HDU 1541 树状数组

    http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意:给你一堆点,每个点右一个level,为其右下方所有点的数量之和,求各个level包含的点数. 题解: ...

  9. hdu 5147 树状数组

    题意:求满足a<b<c<d,A[a]<A[b],A[c]<A[d]的所有四元组(a,b,c,d)的个数 看到逆序对顺序对之类的问题一开始想到了曾经用归并排序求逆序对,结果 ...

随机推荐

  1. C++问题-无法打开包括文件:“GLES2/gl2.h”

    资料来源:http://blog.csdn.net/weizehua/article/details/12623719http://tieba.baidu.com/p/2747715029 问题经过: ...

  2. HDU 1213 How Many Tables (并查集)

    How Many Tables 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/C Description Today is Ig ...

  3. stm32f407 定时器 用的APB1 APB2 及 定时器频率

    上午想要用Timer10做相对精确的延时功能,但是用示波器发现实际延时数值总是只有一半,百思不得其解.仔细查阅各处资料结合实际研究后对stm32f407的14个定时器的时钟做一个总结: 下面来源: h ...

  4. delphi读取excel

    简单的例子 procedure TForm1.Button1Click(Sender: TObject); var ExcelApp,MyWorkBook: OLEVariant; begin ope ...

  5. C语言经典算法100例(一)

    C语言中有有许多经典的算法,这些算法都是许多人的智慧结晶,也是编程中常用的算法,这里面包含了众多算法思想,掌握这些算法,对于学习更高级的.更难的算法都会有很大的帮助,会为自己的算法学习打下坚实的基础. ...

  6. mac 下对 iterm 终端 设置代理

    vi .profile export http_prox="http://xxxx:port" export https_proxy="http://xxxx:port& ...

  7. ID生成器详解

    概述 ID 生成器也叫发号器,它的主要目的就是"为一个分布式系统的数据object产生一个唯一的标识",但其实在一个真实的系统里可能也可以承担更多的作用.概括起来主要有以下几点: ...

  8. 下载Xml文件方法

    #region 下载Xml文件方法 //定义委托 private delegate void DownLoadDelegate(string url, string filename); privat ...

  9. 教你50招提升ASP.NET性能(二十一):避免使用会话状态

    (39)Avoid using session state 招数39: 避免使用会话状态 Where possible, you should try and avoid using session ...

  10. my-view-isnt-reflecting-changes-ive-made-to-the-underlying-tables

    FROM http://sqlstudies.com/2013/01/20/my-view-isnt-reflecting-changes-ive-made-to-the-underlying-tab ...