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. DataSnap Demo:TFDConnection、最大连接数、客户端回叫功能、多线程模拟、压力测试等

    一.限制最大连接数,并验证来访者用户身份: procedure TServerContainer1.DSServer1Connect( DSConnectEventObject: TDSConnect ...

  2. python编程语言缩进格式

    python的缩进格式是python语法中最特别的一点,很多已经习惯了其他语言的朋友再去学python的话,开始会觉的不太 习惯. 怎么看怎么都觉的别扭,也有一些朋友因为这个特别的格式与python失 ...

  3. 【原创】一起学C++ 之指针、数组、指针算术 ---------C++ primer plus(第6版)

    C++ Primer Plus 第6版 指针和数组基本等价的原因在于指针算术! 一.指针 ⑴整数变量+1后,其值将增加1: ⑵指针变量+1后,增加的量等于它指向的类型的字节数: ⑶C++将数组名解析为 ...

  4. Foreign Exchange

     10763 Foreign ExchangeYour non-profit organization (iCORE - international Confederation of Revolver ...

  5. JSP页面时间动态显示 (转载)

    <script type="text/javascript">       function startTime(){        var today=new Dat ...

  6. IOS设备滑动事件

    只要手指触摸屏幕,滑动,从屏幕离开,系统都会产生UIEvent对象类型的事件---当然包括UITouch事件 – touchesBegan:withEvent:   当用户触摸到屏幕时调用方法 – t ...

  7. [译] ASP.NET 生命周期 – ASP.NET 应用生命周期(一)

    概述 ASP.NET 平台定义了两个非常重要的生命周期.第一个是 应用生命周期  (application life cycle),用来追踪应用从启动的那一刻到终止的那一刻.另一个就是 请求生命周期 ...

  8. 关于MySQL Connector/C++那点事儿

    如果从官方直接下载的库使用时遇到类似如下的问题: 原因是官方提供的库文件版本与需要的库版本不匹配,提供的debug版本使用的是MT版本,在debug模式下会出现内存错误,导致crash. TestC. ...

  9. TOPAPI 消息通知机制

    接收用户订阅消息 public class UserSubMain { public static void main(String[] args ) throws ApiException { St ...

  10. ExtJs 4.2.1 复选框数据项动态加载(更新一下)

    最近在做博客项目,后台管理用的是ExtJs4.2.1版本,因为是初学所以在使用的时候也遇到不少的这样或那样的问题,也写了不少这方面的博客,今天要写的博客是关于复选框数据项动态的加载功能,以前也没用过, ...