【poj1195】Mobile phones(二维树状数组)
题目链接:http://poj.org/problem?id=1195
【题意】
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
const int N = ;
typedef long long LL;
int c[N][N], n;
int lowbit(int x)
{
return x & (-x);
}
void update(int x, int y, int num)
{
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= n; j += lowbit(j))
c[i][j] += num;
}
int query(int x, int y)
{
int sum = ;
for(int i = x; i > ; i -= lowbit(i))
for(int j = y; j > ; j -= lowbit(j))
sum += c[i][j];
return sum;
}
int main()
{
int i, m;
scanf("%d%d", &i, &n);
while(scanf("%d", &m), m != )
{
int x1, x2, y1, y2, num;
if(m == )
{
scanf("%d%d%d", &x1, &y1, &num);
x1++, y1++;
update(x1, y1, num);
}
else
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1++, y1++, x2++, y2++;
printf("%d\n", query(x2, y2) - query(x1 - , y2) - query(x2, y1 - ) + query(x1 - , y1 - ));
}
}
return ;
}
【poj1195】Mobile phones(二维树状数组)的更多相关文章
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- Mobile phones_二维树状数组
[题意]给你一个矩阵(初始化为0)和一些操作,1 x y a表示在arr[x][y]加上a,2 l b r t 表示求左上角为(l,b),右下角为(r,t)的矩阵的和. [思路]帮助更好理解树状数组. ...
- poj1195Mobile phones(二维树状数组)
http://poj.org/problem?id=1195 模版题 i写成k了 找了一个多小时没找出来.. #include <iostream> #include<cstring ...
- 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 ...
- (简单) 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 ...
随机推荐
- 关于var关键字的详解
var 在很多语言中都比较常见,到底var是什么,如何应用,下面就笔者常用的javascript.c#对var进行说明: var 是 variable(变量,可变物)的简写.在多种计算机编程语言中,v ...
- PAT 天梯赛 L1-044. 稳赢 【循环】
题目链接 https://www.patest.cn/contests/gplt/L1-044 题意 根据对方给出剪刀石头步 给出对应的胜利出招,每K次 要有一个平局 思路 用一个循环,然后每K次 判 ...
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
转自:http://www.kuqin.com/language/20090806/66164.html 预处理过程扫描源代码,对其进行初步的转换,产生新的源代码提供给编译器.可见预处理过程先于编译器 ...
- JVM(4) 虚拟机性能监控与故障处理工具
1. Sun JDK 监控和故障处理工具 1)jps:JVM process Status Tool,显示指定系统内所有的HotSpot虚拟机进程.可以列出正在运行的虚拟机进程,并显示虚拟机执行主类( ...
- js keyCode(键盘键码)
摘自:http://blog.csdn.net/dyllove98/article/details/8728657 * 网上收集的KeyCode值方便大家查找: keycode 8 = BackSpa ...
- CSS 边距和填充
margin and padding are the two most commonly used properties for spacing-out elements. A margin is t ...
- jQuery动画二级下拉菜单
在线演示 本地下载
- knudson hypothesis 二次突变假说
二次突变假说是由诺丁在1953年提出的,他发现似乎随着年龄的增长,患有癌症的概率有上升.对这种现象有一种解释,即癌症的发生需要多个突变的累积. 克努森在1971通过研究正式地提出该观点.他对具有遗传性 ...
- String创建方式的区别
String str0 = "abc"; String str1 = new String("abc"); 第一句执行后,会在String pool中创建一个& ...
- 关于jquery的each遍历,return只终止当前循环,不好使的解决办法
很奇怪,一般来说return会终止js,但是今天万万没想到的是,jquery 的each循环中,return不好使,做一记录, var result = true; $('input[type=&qu ...