poj1195Mobile phones(二维树状数组)
http://poj.org/problem?id=1195
模版题 i写成k了 找了一个多小时没找出来。。
#include <iostream>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cstdio>
using namespace std;
#define N 1050
#define lowbit(x) (x&(-x))
int n,c[N][N];
void add(int i,int j,int da)
{
int k;
while(i<=n)
{
k = j;
while(k<=n)
{
c[i][k]+=da;
k+=lowbit(k);
}
i+=lowbit(i);
}
}
int getsum(int i,int j)
{
int sum=,k;
while(i)
{
k = j;
while(k)
{
sum+=c[i][k];
k-=lowbit(k);
}
i-=lowbit(i);
}
return sum;
}
int main()
{
int k,a,b,cc,d,t;
cin>>t>>n;
memset(c,,sizeof(c));
while(scanf("%d",&k),k!=)
{
if(k==)
{
scanf("%d%d%d",&a,&b,&cc);
add(a+,b+,cc);
}
else if(k==)
{
scanf("%d%d%d%d",&a,&b,&cc,&d);
a++;b++;cc++;d++;
printf("%d\n",getsum(cc,d)-getsum(a-,d)-getsum(cc,b-)+getsum(a-,b-));
}
}
return ;
}
poj1195Mobile 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]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- 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 ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones【二维树状数组】
<题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...
随机推荐
- Cassandra1.2文档学习(14)—— 事务和并发控制
参考文档:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/dml/dml_about_ ...
- linux命令 chattr超级权限控件
linux命令:chattr 1.作用 修改ext2和ext3文件系统属性(attribute),使用权限超级用户. linux命令:chattr 1.作用修改ext2和ext3文件系统属性(at ...
- PHP学习之环境搭建
计算机环境 win7 64位 搭建 apache-httpd-2.2-win64 + php-5.3.6-Win32-VC9-x64 +MySQL_5.5.13_winx64开发环境 参考: ...
- 一个基于python的即时通信程序
5月17日更新: 广播信息.用户列表.信息确认列表以及通信信息,从原来的用字符串存储改为使用字典来存储,使代码更清晰,更容易扩展,具体更改的格式如下: 广播信息(上线): { 'status': 信息 ...
- JS 判断一个字符串是否包含在一个数组中
var arr = ["白色", "黑色", "红色", "粉色"]; var sel = "黑色" ...
- UIImagePickerController拍照与摄像(转)
转载自:http://blog.sina.com.cn/s/blog_68edaff101019ppe.html (2012-11-23 14:38:40) 标签: ios iphone 拍照 摄像 ...
- (转载)Cocos2dx-OpenGL ES 2.0教程:你的第一个三角形(1)
前言 在本系列教程中,我会以当下最流行的2D引擎Cocos2D-X为基础,介绍OpenGL ES 2.0的一些基本用法.本系列教程的宗旨是OpenGL扫盲,让大家在使用Cocos2D-X过程中,知其然 ...
- resin access.log format配置详解
The access log formatting variables follow the Apache variables: %b result content length %D tim ...
- iOS人脸识别核心代码(备用)
for (int i = 0; i < 1; i++) { //< [arr count]; i++) { CIFaceFeature *feature = [arr objectAtIn ...
- appStore上传苹果应用程序软件发布流程(之前都是同事发,复制一份备用)
首先确定帐号是否能发布, https://developer.apple.com/account,如果你打开Provisioning Portal,然后点击DisTribution看到的是下图中那样, ...