POJ_1195 Mobile phones 【二维树状数组】
题目链接: id=1195" rel="nofollow">http://poj.org/problem?id=1195
纯纯的二维树状数组,不解释。仅仅须要注意一点,由于题目中的数组从0開始计算。所以维护的时候须要加1。由于树状数组的下标是不能为1的
代码:
#include <iostream>
#include <cstdio>
#define N 1030
using namespace std;
int c[N][N];
int cas,n,x,y,a,l,b,r,t;
int Lowbit(int x)
{
return x & (-x);
}
void Updata(int x,int y,int a)
{
int i,k;
for(i=x; i<=n; i+=Lowbit(i))
for(k=y; k<=n; k+=Lowbit(k))
c[i][k]+=a;
}
int Getsum(int x,int y)
{
int i,k,sum = 0;
for(i=x; i>0; i-=Lowbit(i))
for(k=y; k>0; k-=Lowbit(k))
sum += c[i][k];
return sum;
}
int main()
{
scanf("%d%d",&cas,&n);
while(~scanf("%d",&cas))
{
if(cas==1)
{
scanf("%d%d%d",&x,&y,&a);
Updata(x+1,y+1,a);
}
if(cas==2)
{
scanf("%d%d%d%d",&l,&b,&r,&t);
int a=Getsum(r+1,t+1)-Getsum(l,t+1)-Getsum(r+1,b)+Getsum(l,b);
printf("%d\n",a);
}
if(cas==3)
return 0;
}
return 0;
}
POJ_1195 Mobile phones 【二维树状数组】的更多相关文章
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- 【poj1195】Mobile phones(二维树状数组)
题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- Mobile phones_二维树状数组
[题意]给你一个矩阵(初始化为0)和一些操作,1 x y a表示在arr[x][y]加上a,2 l b r t 表示求左上角为(l,b),右下角为(r,t)的矩阵的和. [思路]帮助更好理解树状数组. ...
- poj1195Mobile phones(二维树状数组)
http://poj.org/problem?id=1195 模版题 i写成k了 找了一个多小时没找出来.. #include <iostream> #include<cstring ...
- poj_1195Mobile phones,二维树状数组
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
随机推荐
- 正则过滤html的标签
$('#Text').find('br').remove();//移除br标签 let content = $('#smsText').html().replace(/ /g, ' ').replac ...
- java中for循环执行过程
for (int j = 0; j < newSize; j++) { //执行todo } 1.首先变量j初始化为0 2.然后j=0的值跟newSize进行比较,假如为true,则执行{}里面 ...
- jQuery 实战读书笔记之第五章:使用 jQuery 操作页面
html 如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> &l ...
- makefile的选项LDFLAGS和LIBS的区别
LDFLAGS是选项,LIBS是要链接的库.都是喂给ld的,只不过一个是告诉ld怎么吃,一个是告诉ld要吃什么. 网上不难搜索到上面这段话.不过“告诉ld怎么吃”是什么意思呢? 看看如下选项: LDF ...
- Oracle的REGEXP_INSTR函数简单使用方法
REGEXP_INSTR函数让你搜索一个正則表達式模式字符串. 函数使用输入字符集定义的字符进行字符串的计算. 它返回一个整数,指示開始或结束匹配的子位置.这取决于return_option參数的值. ...
- redis-3.0.6安装
此redis用来缓存跨屏账户绑定信息,安装步骤如下: ssh root@redis.td.com ,注意是root用户 tar -xzvf /nfs/install/softs/redis-3.0.4 ...
- 【JMeter性能测试】之学习资料总结(持续更新)
本人测试小白,总结一下JMeter性能测试相关文档进行转载学习,下面会贴出原文作者以示感谢: JMeter性能测试学习地址:http://www.ltesting.net/ceshi/open/kyx ...
- python文章的抓取
# coding = utf-8import urllibimport sysimport urllibimport jsonimport socketimport timesys.path.appe ...
- 利用JQuery jsonp实现Ajax跨域请求 .Net 的*.handler 和 WebService,返回json数据
1:跨域请求handler一般处理程序 using System; using System.Collections.Generic; using System.Web; using System.W ...
- 【ask】vc11 sln文件里加入新的vcxproj已有vcxproj里的用户宏没有自动复制过来
今天在quick-cocos2d-x生成的sln,需要添加一个新的自己的lib,以前就是直接把.h和.cc文件直接添加过去(为了省事呗),今天时间宽裕索性还是新建一个vcxproj吧,然后用静态lib ...