#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <algorithm> using namespace std;
int map[1015][1015]; void update(int x,int y, int n)
{
for(int i=x;i<=1005;i+=(i&(-i)))
{
for(int j=y;j<=1005;j+=(j&(-j)))
{
map[i][j]+=n;
}
}
} int sum(int x,int y)
{
int s = 0;
for(int i=x;i>=1;i-=(i&(-i)))
{
for(int j=y;j>=1;j-=(j&(-j)))
{
s+=map[i][j];
}
}
return s;
} int main(){
// freopen("exp.in","r",stdin);
int t, q;
char s[3];
int x1,x2,y1,y2,n1;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
printf("Case %d:\n",i);
memset(map,0,sizeof(map));
for(int j=1;j<=1005;j++)
for(int k = 1;k<=1005;k++)
update(j,k,1); scanf("%d",&q);
for(int j=1;j<=q;j++)
{ scanf("%s",s);
if(s[0]=='S')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
printf("%d\n",sum(x2+1,y2+1)+sum(x1,y1)-sum(x1,y2+1)-sum(x2+1,y1));
}
else if(s[0]=='A')
{
scanf("%d%d%d",&x1,&y1,&n1);
update(x1+1,y1+1,n1);
}
else if(s[0]=='D')
{
scanf("%d%d%d",&x1,&y1,&n1);
int v = sum(x1+1,y1+1)+sum(x1,y1)-sum(x1,y1+1)-sum(x1+1,y1);
n1=(n1-v>0)?v:n1;
update(x1+1,y1+1,-n1);
}
else if(s[0]=='M')
{
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n1);
int v = sum(x1+1,y1+1)+sum(x1,y1)-sum(x1,y1+1)-sum(x1+1,y1);
n1=(n1-v)>0?v:n1;
update(x1+1,y1+1,-n1);
update(x2+1,y2+1,n1);
}
}
}
// fclose(stdin);
return 0;
}

Code From Hdu 1982

版权声明:本文为博主原创文章,未经博主允许不得转载。

Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏的更多相关文章

  1. A simple problem 分类: 哈希 HDU 2015-08-06 08:06 1人阅读 评论(0) 收藏

    A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...

  2. 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏

    Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

  3. DataGridView 列大写、列只能输入数字 分类: DataGridView 2014-12-07 08:40 332人阅读 评论(0) 收藏

    列大写: 说明:调用EditingControlShowing事件 private void dgvGoods_EditingControlShowing(object sender, DataGri ...

  4. 快速幂取模 分类: ACM TYPE 2014-08-29 22:01 95人阅读 评论(0) 收藏

    #include<stdio.h> #include<stdlib.h> //快速幂算法,数论二分 long long powermod(int a,int b, int c) ...

  5. HDU 2042 不容易系列之二 [补6.24] 分类: ACM 2015-06-26 20:40 9人阅读 评论(0) 收藏

    不容易系列之二 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  6. ZOJ 3810 Pretty Poem 分类: ACM 2015-05-17 14:40 83人阅读 评论(0) 收藏

    Pretty Poem Time Limit: 2 Seconds     Memory Limit:65536 KB Poetry is a form of literature that uses ...

  7. 多校3-Magician 分类: 比赛 2015-07-31 08:13 4人阅读 评论(0) 收藏

    Magician Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  8. highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏

    /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...

  9. OC基础知识总结 分类: ios学习 OC 2015-06-26 17:58 58人阅读 评论(0) 收藏

    //OC: Objective-C, 面向对象的C语言 //OC与C的区别 //1.OC是C的超集, C语言的所有语法都可以在OC中使用 //2.OC是面向对象 //3.OC是一门运行时语言 //4. ...

随机推荐

  1. 文本处理命令--wc、sed

    一.wc wc命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 测试文件内容: (my_python_env)[root@hadoop26 ~]# cat test hnlinu ...

  2. PHP 实现下载文件到本地

    只需要在php文件中设置请求头就可以了,创建download.php文件,代码如下: $fileName = $_GET['filename']; //得到文件名 header( "Cont ...

  3. PHP-PCRE正则表达式函数

    PCRE正则表达式函数 PCRE字符类 \\b        词边界 \\d        匹配任意数字 \\s        匹配任意空白,如TAB制表符或空格 \\t        匹配一个TAB ...

  4. .ascx.g.cs文件不能生成 The name ‘InitializeControl’ does not exist in the current context - Visual Web part Sharepoint

    InitializeControl doesn't exsit When using visual studio 2012 for developing SharePoint 2013 Visual ...

  5. 解决dropdownlist postback 在 iphone UIwebview 失效的问题

    原因: IPhone UIWebView 的 用户代理 User Agent 在ASP.NET 4.0环境下是不识别的:所以ASP.NET提供了一个默认的,低级的不包括javascript的页面版本 ...

  6. GetType() 和typeof() 的区别

    GetType() 非强类型,支持跨程序集发射,用来支持动态引用, A obja=new A(); Type t=obja.GetType() typeof() 强类型,静态的 Type t=type ...

  7. 3.第一个python程序

    学习任何一门语言的第一步,首先要写个'hello world',这算是程序员的一个传统.但在写之前,还有注意几个问题. 首先,python是一门脚本语言,而脚本语言的特点就是:我们写的代码会先由解释器 ...

  8. Ruby实现wordCounter

    做解密发现的: m={} File.open("test1.txt") do |f| f.each_line do |line| line.chomp! #去除每行结尾的回车(\n ...

  9. Mysql账号管理

    一 用户添加 通过insert 方式添加用户 insert into mysql.user(Host,User,Password) values("localhost"," ...

  10. Mysql数据库基本配置

    一 数据库基本配置包括编码方式 (安装环境是在linux下) 1.1 进入数据库 开启数据库服务:service mysqld start/restart(如果开启话可以重启) 关闭数据库服务:ser ...