树状数组,开始的时候wa了,后来看看,原来是概率论没学好,以为求(L,B) - (R,T) 矩阵内的和只要用sum(R+1,T+1) - sum(L,B) 就行了,。傻x了。。

必须 sum(R,T) - sum(L,T) - sum(R,B) + sum(L,B) ;  (R,T 已经自加1)   诫之。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1027 int c[N][N];
int n; int lowbit(int x)
{
return x&(-x);
} void modify(int x,int y,int val)
{
for(int i=x;i<=n;i+=lowbit(i))
{
for(int j=y;j<=n;j+=lowbit(j))
{
c[i][j] += val;
}
}
} int sum(int x,int y)
{
int res = ;
for(int i=x;i>;i-=lowbit(i))
{
for(int j=y;j>;j-=lowbit(j))
{
res += c[i][j];
}
}
return res;
} int main()
{
int op,L,B,R,T,A,X,Y;
while(scanf("%d",&op)!=EOF)
{
if(op == )
break;
else if(op == )
{
memset(c,,sizeof(c));
scanf("%d",&n);
}
else if(op == )
{
scanf("%d%d%d",&X,&Y,&A);
X++;Y++;
modify(X,Y,A);
}
else if(op == )
{
scanf("%d%d%d%d",&L,&B,&R,&T);
R++;T++;
printf("%d\n",sum(R,T)-sum(L,T)-sum(R,B)+sum(L,B));
}
}
return ;
}

POJ 1195 Mobile Phones的更多相关文章

  1. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  2. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  3. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  4. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  5. POJ 1195 Mobile phones (二维树状数组)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  6. 题解报告:poj 1195 Mobile phones(二维BIT裸题)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  7. poj 1195 Mobile phones(二维树状数组)

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

  8. ●POJ 1195 Mobile phones

    题链: http://poj.org/problem?id=1195 题解: 二维树状数组 #include<cstdio> #include<cstring> #includ ...

  9. poj 1195 Mobile phones 解题报告

    题目链接:http://poj.org/problem?id=1195 题目意思:有一部 mobie phone 基站,它的面积被分成一个个小正方形(1 * 1 的大小),所有的小正方形的面积构成了一 ...

  10. poj 1195 - Mobile phones(树状数组)

    二维的树状数组,,, 记得矩阵的求和运算要想好在写.... 代码如下: #include <cstdio> #include <cstdlib> #include <cm ...

随机推荐

  1. PHP学习笔记:APACHE配置虚拟目录、一个站点使用多域名配置方式

    我用的是xmapp lite2016的集成包,配置虚拟目录教程如下: 找到httpd-vhosts.conf这个文件,这个文件一般是在xampp\apache\conf\extra这个路径下面,找不到 ...

  2. PHP学习笔记:等比例缩放图片

    直接上代码,imgzip($src,$newwid,$newhei)这个函数带进去的分别是原图片.缩放要求的宽度.缩放的长度.代码都备注了,不懂可以留言哈哈 <?php //压缩图片 缩略图 $ ...

  3. jdk1.8 ThreadPoolExecutor实现机制分析

    ThreadPoolExecutor几个重要的状态码字段 private static final int COUNT_BITS = Integer.SIZE - 3; private static ...

  4. .NET Core Roadmap

    This post was written by Scott Hunter. It has been about two weeks since we shipped .NET Core / ASP. ...

  5. 桥牌笔记:Skill Level 4 D8

    西拿黑桃K.A后,转攻小方块. 看来只有一个小红桃失张了.飞方块没有必要冒险.但将牌分布4-0时会有点麻烦.

  6. 基于Retrofit+RxJava的Android分层网络请求框架

    目前已经有不少Android客户端在使用Retrofit+RxJava实现网络请求了,相比于xUtils,Volley等网络访问框架,其具有网络访问效率高(基于OkHttp).内存占用少.代码量小以及 ...

  7. android 音乐播放器简单实现

    package com.zhangbz.musicplayer; import java.io.File; import android.app.Activity; import android.me ...

  8. 关于破解IDEA

    博客的意义就在于分享 哈哈 今天想装个 IDEA玩玩 去官网 下了个 安装包 想破解 结果度娘 帮解决了 直接po方法 很简单 就是安装好注册的时候 选择 License server ,填 http ...

  9. XP重装之后蓝屏

    最近帮公司的电脑重装XP系统,发现重装之后电脑重启的时候蓝屏 解决方法:开机-->f2-->找到SATA Configration --> 选择ide 重启,就ok了

  10. Handler、Looper、MessageQueue、Thread源码分析

    关于这几个之间的关系以及源码分析的文章应该挺多的了,不过既然学习了,还是觉得整理下,印象更深刻点,嗯,如果有错误的地方欢迎反馈. 转载请注明出处:http://www.cnblogs.com/John ...