poj 1195 - Mobile phones(树状数组)
二维的树状数组,,,
记得矩阵的求和运算要想好在写。。。。
代码如下:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <map> #define M 1100
#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define LLU unsigned long long
#define lowbit(x) (x&-x) using namespace std; LL c[M][M];
int n;
void add(int x, int y, int a)
{
for(int i = x; i <= n; i+=lowbit(i))
for(int j = y; j <= n; j+=lowbit(j))
c[i][j] += a;
}
LL sum(int l, int r, int ll, int rr)
{
LL s1 = 0;
for(int i = l-1; i > 0; i-=lowbit(i))
for(int j = r-1; j > 0; j -= lowbit(j))
s1+=c[i][j];
LL s2 = 0;
for(int i = l-1; i > 0; i-=lowbit(i))
for(int j = rr; j > 0; j -= lowbit(j))
s2+=c[i][j];
LL s3 = 0;
for(int i = ll; i > 0; i-=lowbit(i))
for(int j = r-1; j > 0; j -= lowbit(j))
s3+=c[i][j];
LL s = 0;
for(int i = ll; i > 0; i-=lowbit(i))
for(int j = rr; j > 0; j-=lowbit(j))
s+=c[i][j];
return s+s1-s2-s3;
}
int main ()
{
int t, x, y, a, l, r, ll, rr;
scanf("%d%d", &t, &n);
while(scanf("%d", &t), t!=3)
{
if(t==1)
{
scanf("%d%d%d", &x, &y, &a);
add(x+1, y+1, a);
}
else
{
scanf("%d%d%d%d", &l, &r, &ll, &rr);
printf("%lld\n", sum(l+1, r+1, ll+1, rr+1));
}
}
return 0;
}
poj 1195 - Mobile phones(树状数组)的更多相关文章
- POJ 1195 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18489 Accepted: 8558 De ...
- Mobile phones POJ - 1195 二维树状数组求和
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones(二维树状数组)
Mobile phones Time Limit: 5000MS Mem ...
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones (二维树状数组或线段树)
偶然发现这题还没A掉............速速解决了............. 树状数组和线段树比较下,线段树是在是太冗余了,以后能用树状数组还是尽量用......... #include < ...
随机推荐
- SpringMVC集成缓存框架Ehcache
在互联网应用中,应用并发比传统企业及应用会高出很多.解决并发的根本在于系统的响应时间与单位时间的吞吐量.思路可分为:一减少系统的不必要开支(如缓存),二是提高系统单位时间内的运算效率(如集群). 在硬 ...
- PLSQLDeveloper 提示不能初始化?
原因: oracle数据库是64位的,而 PLSQL Developer 只有32位的! 下载PLSQL_Developer地址: http://pan.baidu.com/share/link?sh ...
- VaR实现实证
投资组合Var计算实例 http://financetrain.com/analytical-approach-to-calculating-var-variance-covariance-metho ...
- 用c和c++的方式实现栈
#include <stdio.h> #include <stdlib.h> #include <assert.h> struct LinkNode { int d ...
- WinForm用户自定义控件,在主窗体加载时出现闪烁;调用用户控件出现闪烁,需要鼠标才能够显示
转载自:http://www.dotblogs.com.tw/rainmaker/archive/2012/02/22/69811.aspx 解决方案: 在调用用户控件的窗体里面添加一下代码: pro ...
- MVC的自定义动作过滤器(一)
感谢好朋友wolfy在园子里的很多有价值的文章,方便了很多朋友,向榜样学习,开始自己的总结之旅:) 遇到问题: 1.http://q.cnblogs.com/q/67382/#a_150210 //添 ...
- Windows cmd命令搜索顺序
一.在cmd中执行一个不带后缀的命令(不带路径),首先会在无后缀的系统命令(如cd.dir等)中搜索,如果找到了就执行该命令, (dir是无后缀的系统命令所以优先执行,无视当前目录中的dir.exe) ...
- 20151207Study
Liberal lawmakers proposed a bill to reduce the cost of medicine for older Americans.自由主义立法者提出一条减少老年 ...
- JavaScript 之 for语句
示例: for(var i = 6; i--;){ console.log(i); } 这里的执行结果是5,4,3,2,1,0 W3C有关for的解释这里 for(语句1; 语句2;语句3){ con ...
- Gson实现自定义解析json格式
客户端跟服务器交互的时候我们使用json实现 但是 在交互的时候除了传送json对象数据意外 我们还需要传输标志位等 比如我们现在的交互方式格式 对象 { "data": { &q ...