Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a square can change because a phone is moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row and the column of the matrix.

Write a program, which receives these reports and answers queries about the current total number of active mobile phones in any rectangle-shaped area.

Input

The input is read from standard input as integers and the answers to the queries are written to standard output as integers. The input is encoded as follows. Each input comes on a separate line, and consists of one instruction integer and a number of parameter integers according to the following table. 

The values will always be in range, so there is no need to check them. In particular, if A is negative, it can be assumed that it will not reduce the square value below zero. The indexing starts at 0, e.g. for a table of size 4 * 4, we have 0 <= X <= 3 and 0 <= Y <= 3.

Table size: 1 * 1 <= S * S <= 1024 * 1024 
Cell value V at any time: 0 <= V <= 32767 
Update amount: -32768 <= A <= 32767 
No of instructions in input: 3 <= U <= 60002 
Maximum number of phones in the whole table: M= 2^30 

Output

Your program should not answer anything to lines with an instruction other than 2. If the instruction is 2, then your program is expected to answer the query by writing the answer as a single line containing a single integer to standard output.

Sample Input

0 4
1 1 2 3
2 0 0 2 2
1 1 1 2
1 1 2 -1
2 1 1 2 3
3

Sample Output

3
4 板子题
 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000") using namespace std;
typedef long long LL ;
const int maxn = 2e3 + ;
int n, k, c[maxn][maxn];
void updata(int x, int y, int z) {
for (int i = x ; i <= n ; i += lowbit(i))
for (int j = y ; j <= n ; j += lowbit(j))
c[i][j] += z;
}
int sum(int x, int y) {
int ret = ;
for (int i = x ; i > ; i -= lowbit(i))
for (int j = y ; j > ; j -= lowbit(j))
ret += c[i][j];
return ret;
}
int main() {
scanf("%d%d", &k, &n);
while() {
scanf("%d", &k);
if (k == ) {
int x, y, z;
sfff(x, y, z);
x++, y++;
updata(x, y, z);
}
if (k == ) {
int x1,y1,x2,y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1++, y1++, x2++, y2++;
int ans = sum(x2, y2) - sum(x1 - , y2) - sum(x2, y1 - ) + sum(x1 - , y1 - );
printf("%d\n", ans);
}
if (k == ) break;
}
return ;
}
												

Mobile phones POJ - 1195 二维树状数组求和的更多相关文章

  1. POJ 1195 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18489   Accepted: 8558 De ...

  2. poj 2029 二维树状数组

    思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...

  3. poj 3378 二维树状数组

    思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...

  4. poj 2155 (二维树状数组 区间修改 求某点值)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33682   Accepted: 12194 Descript ...

  5. HihoCoder1336 Matrix Sum(二维树状数组求和)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given an N × N matrix. At the beginning every element ...

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

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

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

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

  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 二维树状数组

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

随机推荐

  1. MySQL数据库怎么截取字符串?

    函数: 1.从左开始截取字符串 left(str, length) 说明:left(被截取字段,截取长度) 例:select left(content,200) as abstract from my ...

  2. java核心技术 笔记

    一 . 总览 1. 类加载机制:jdk内嵌的class_loader有哪些,类加载过程.--后面需要补充 2. 垃圾收集基本原理,常见的垃圾收集器,各自适用的场景.--后面需要补充 3. 运行时动态编 ...

  3. 一键部署pxe环境

    系统:Centos6.5 环境:VMware Workstation12 #!/bin/bash # Please prepare CentOS ISO image first # root pass ...

  4. Python3 Tkinter-Entry

    1.创建 from tkinter import * root=Tk() t1=Entry(root) t1.pack() root.mainloop() 2.绑定变量 from tkinter im ...

  5. 一键部署 Docker Datacenter ---简化docker数据中心安装步骤

    DDC 简介 2016年2月下旬,Docker发布了企业级容器管理和服务部署的整体解决方案平台-Docker Datacenter,简称DDC.DDC 有三个组件构成:1. Docker Univer ...

  6. hibernate 异常a different object with the same identifier value was already associated with the session

    在使用hibernate的时候发现了一个问题,记录一下解决方案. 前提开启了事务和事务间并无commit,进行两次save,第二次的时候爆出下面的异常a different object with t ...

  7. css重修之书(一):如何用css制作比1px更细的边框

    如何用css制作比1px更细的边框 在项目的开发过程中,我们常常会使用到border:1px solid xxx,来对元素添加边框: 可是1px的border看起来还是粗了一些粗,不美观,那么有什么方 ...

  8. mysql source 恢复 sql数据time_zone报错 已解决

    报了一些变量的错误,类似于"time_zone" 等错误 解决: [root@iz8vbilqy0q9v8tds55bqzz conf.d]# vi /etc/my.cnf [my ...

  9. activiti工作流已办和待办查询sql

    最近项目中遇到一个问题,需要activiti的工作流表和业务表关联分页查询,然而我对于工作流的查询并不太熟悉,所以学习并总结如下. 想看看activiti到底怎么查询的待认领和待办.已办的查询sql, ...

  10. 自定义类属性设置及setter、getter方法的内部实现

    属性是可以说是面向对象语言中封装的一个体现,在自定义类中设置属性就相当于定义了一个私有变量.设置器(setter方法)以及访问器(getter方法),其中无论是变量的定义,方法的声明和实现都是系统自动 ...