#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1300][1300];
int s;
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int y,int d)
{
for(int i=x;i<=s;i+=lowbit(i))
for(int j=y;j<=s;j+=lowbit(j))
a[i][j]+=d;
}
int sum(int x,int y)
{
int ret=0;
for(int i=x;i>0;i-=lowbit(i))
for(int j=y;j>0;j-=lowbit(j))
ret+=a[i][j];
return ret;
}
int main()
{
while(scanf("%d%d",&s,&s)!=EOF)
{
memset(a,0,sizeof(a));
int n,x,y,d,xt,yt;
while(scanf("%d",&n))
{
if(n==3) break;
if(n==1)
{
scanf("%d%d%d",&x,&y,&d);
x++,y++;
add(x,y,d);
}
if(n==2)
{
scanf("%d%d%d%d",&x,&y,&xt,&yt);
x++,y++,xt++,yt++;
int ans=sum(xt,yt)-sum(xt,y-1)-sum(x-1,yt)+sum(x-1,y-1);
cout<<ans<<endl;
}
}
}
return 0;
}

poj_1195Mobile 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. poj1195Mobile phones(二维树状数组)

    http://poj.org/problem?id=1195 模版题 i写成k了 找了一个多小时没找出来.. #include <iostream> #include<cstring ...

  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. SQL SERVER-主键的建立和删除

    PRIMARY KEY 约束唯一标识数据库表中的每条记录.主键必须包含唯一的值.主键列不能包含 NULL 值.每个表都应该有一个主键,并且每个表只能有一个主键.主键约束操作包含了添加约束和删除约束,修 ...

  2. SQL SERVER-NULL

    SQL SERVER判断NULL的函数 ISNULL().NVL().IFNULL() 和 COALESCE() 函数 来自为知笔记(Wiz)

  3. SQL SERVER-identity | @@identity | scope_identity

    主键自增 IDENTITY(1,1),MS SQL Server 使用 IDENTITY 关键字来执行 auto-increment 任务. 在上面的实例中,IDENTITY 的开始值是 1,每条新记 ...

  4. HDU 3240

    求卡特兰数前N项的和模M. 直接求必定是不可能的,卡特兰数太大了.想了好久,本打算把位数拆成素数相乘,然后记录下各素数的个数计算.可惜,TLE....因为N太大了. 除法必定是要用到逆元的,但分母与M ...

  5. Revolution Platform

    Revolution Platform 黑暗的极权统治现实 异类的处境 独孤的存在 觉者的形成 信仰的确立 信仰的产物 完整的思想理论 反抗与信仰的一致 反抗的超理性的智慧论 反抗的纯理性的方法论 反 ...

  6. 【BZOJ3270】博物馆 概率DP 高斯消元

    链接: #include <stdio.h> int main() { puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢"); puts("网 ...

  7. libLAS1.8.0 编译和配置(VS2013+Win7 64)(一)

    libLAS 是一个用来读写三维激光雷达数据(LiDAR) 的 C++ 库.在学习.科研和研发中都会广泛运用.怎样编译和配置自己所须要版本号的libLAS库确是一件麻烦耗时的事情. 笔者在Win7 6 ...

  8. java Semaphore信号亮-同意多个任务同一时候訪问这个资源--thinking in java21.7.6

    package org.rui.thread.newc.semaphore; import java.util.ArrayList; import java.util.List; import jav ...

  9. LA 6437 Power Plant (prim最小生成树)

    还是裸的最小生成树 #include<bits/stdc++.h> using namespace std; int T,N,M,P,K,a,b,c; int dist[1020],m[1 ...

  10. 获取json数据后在 地图上打点,根据 json不断移动点的位置

    <?php echo <<<_END <!doctype html> <html> <head> <meta charset=&quo ...