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(二维树状数组)的更多相关文章

  1. POJ 1195:Mobile phones 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16893   Accepted: 7789 De ...

  2. 【poj1195】Mobile phones(二维树状数组)

    题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...

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

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

  4. poj_1195Mobile phones,二维树状数组

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...

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

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

  6. 【POJ1195】【二维树状数组】Mobile phones

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

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

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

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

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

  9. POJ 1195 Mobile phones【二维树状数组】

    <题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...

随机推荐

  1. √GMAP.NET 地图

    深入理解最强桌面地图控件GMAP.NET ---[更新]百度地图 enjoyeclipse 2013-11-18 22:23 阅读:3897 评论:20     深入理解最强桌面地图控件GMAP.NE ...

  2. 使用urllib2的HttpResponse导致内存不回收(内存泄漏)

    问题出现环境:python 2.7.1(X)及以下, Windows(或CentOS) 这个问题产生在lib/urllib2.py的line 1174 (python 2.7.1),导致形成了cycl ...

  3. unity3d应用内分享(微信、微博等)的实现

    问题:如何在unity3d的游戏中实现分享功能,如图 思路: 1.分享功能的实现方式有多种,较方便快捷的一种是直接调用android的API来调出系统的分享界面 2.unity3d里面调用androi ...

  4. 使用WebGL实现一个Viewer来显示STL文件

    关键字:WebGL,STL,ThreeJS,Chrome,Viewer,Python3.4, HTML5,Canvas. OS:Windows 10. 本文介绍如何使用ThreeJS来实现一个WebG ...

  5. (转)MVC 3 数据验证 Model Validation 详解

    继续我们前面所说的知识点进行下一个知识点的分析,这一次我们来说明一下数据验证.其实这是个很容易理解并掌握的地方,但是这会浪费大家狠多的时间,所以我来总结整理一下,节约一下大家宝贵的时间. 在MVC 3 ...

  6. PHP内置函数

    1 变量函数 a.is_xxx函数用来判断变量类型       is_int.is_integer.is_long,判断变量是否是整型       is_float.is_double.is_real ...

  7. 操作数据(insert、update、delete)

    插入数据 使用Insert Into 插入 if(exists(select * from sys.databases where name = 'webDB')) drop database web ...

  8. 巧用九宫格以减少UI资源量

    UI资源量对资源包大小和内存的影响 UI资源具有以下特点: (1)UI资源几乎都是图片,而图片是最占资源量的资源类型之一. (2)Unity不支持外部压缩,即使在外部将一个10MB的图片压缩到只剩1M ...

  9. Mac - 更新 Ruby

    因为准备在项目中使用bootstrap,在安装bootstrap过程中提示需要Ruby的版本在1.9.2以上,而目前使用的Ruby版本是Mac系统自带的1.8.7.所以需要对Ruby进行升级.这里使用 ...

  10. main函数(本文较老,仅作参考)

    Xcode4.2之前的main函数如下: int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePoo ...